I am trying to perform a relational update using an innjer join and can't seem to get the syntax correct.
The rows are as follows:
Catalogue.Category_ID
Catalogue.Visible
Categories.Category_ID
Categories.Category_Name
I am trying to update the value of the visible field when the category ID numbers match and correspond the the correct name.
UPDATE `Catalogue`
SET `Visible` = '0'
FROM `Catalogue`
INNER JOIN `Categories`
ON Catalogue.Category_ID = Categories.Category_ID
AND Categories.Category_Name = 'Bases'
Apologies if it comes down to a stupid syntax mistake, i'm not the most experienced with relational databases.
The MySQL Update Join is used for executing the update statement together with the implementation of INNER JOIN and LEFT JOIN MySQL clauses in the server. This Update JOIN clause in MySQL helps to retrieve the data records from the related database tables along with modifying them with the query.
It is possible to join two or more tables in an UPDATE query.
I believe this is the proper syntax:
UPDATE `Catalogue`
INNER JOIN `Categories`
ON Catalogue.Category_ID = Categories.Category_ID
AND Categories.Category_Name = 'Bases'
SET `Visible` = '0'
You are using TSQL
syntax, here's for MySQL
UPDATE `Catalogue`
INNER JOIN `Categories`
ON Catalogue.Category_ID = Categories.Category_ID
SET `Visible` = '0'
WHERE Categories.Category_Name = 'Bases'
if you want to shorten the query, use ALIAS
UPDATE Catalogue a
INNER JOIN Categories b
ON a.Category_ID = b.Category_ID
SET Visible = '0'
WHERE b.Category_Name = 'Bases'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With