[英]MySQL Inner Join Update
I am trying to perform a relational update using an innjer join and can't seem to get the syntax correct. 我试图使用innjer连接执行关系更新,似乎无法使语法正确。
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. 我试图在类别ID号匹配时更新可见字段的值,并对应正确的名称。
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. 抱歉,如果归结为一个愚蠢的语法错误,我不是最有经验的关系数据库。
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
您正在使用TSQL
语法,这里是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
如果要缩短查询,请使用ALIAS
UPDATE Catalogue a
INNER JOIN Categories b
ON a.Category_ID = b.Category_ID
SET Visible = '0'
WHERE b.Category_Name = 'Bases'
I believe you're looking for: 我相信你在寻找:
UPDATE 'Catalogue' SET 'Visible' = '0' FROM 'Catalogue' INNER JOIN 'Categories' ON Catalogue.Category_ID = Categories.Category_ID
WHERE Categories.Category_NAME = 'Bases'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.