8

我正在尝试使用 innjer 连接执行关系更新,但似乎无法正确获取语法。

行如下:

Catalogue.Category_ID
Catalogue.Visible

Categories.Category_ID
Categories.Category_Name

当类别 ID 号匹配并对应正确的名称时,我正在尝试更新可见字段的值。

UPDATE `Catalogue` 
SET `Visible` = '0' 
FROM `Catalogue` 
INNER JOIN `Categories` 
  ON Catalogue.Category_ID = Categories.Category_ID 
  AND Categories.Category_Name = 'Bases'

如果归结为愚蠢的语法错误,我深表歉意,我对关系数据库不是最有经验的。

4

3 回答 3

17

我相信这是正确的语法:

UPDATE `Catalogue` 
INNER JOIN `Categories` 
  ON Catalogue.Category_ID = Categories.Category_ID 
  AND Categories.Category_Name = 'Bases'
SET `Visible` = '0' 
于 2013-07-26T20:15:39.167 回答
3

您正在使用TSQL语法,这里是MySQL

UPDATE `Catalogue` 
       INNER JOIN `Categories`
           ON Catalogue.Category_ID = Categories.Category_ID

SET `Visible` = '0' 
WHERE Categories.Category_Name = 'Bases'

如果要缩短查询,请使用ALIAS

UPDATE Catalogue a 
       INNER JOIN Categories b
           ON a.Category_ID = b.Category_ID

SET    Visible = '0' 
WHERE  b.Category_Name = 'Bases'
于 2013-07-26T20:16:07.000 回答
1

我相信您正在寻找:

UPDATE 'Catalogue' SET 'Visible' = '0' FROM 'Catalogue' INNER JOIN 'Categories' ON Catalogue.Category_ID = Categories.Category_ID
WHERE Categories.Category_NAME = 'Bases'
于 2013-07-26T20:16:19.107 回答