1

如何在 MySQL 中执行以下操作:

UPDATE PartTbl SET aFlag = 0 
WHERE PartId = (SELECT PartId FROM CategoryTbl WHERE cat = 100)
4

3 回答 3

1
UPDATE PartTbl SET aFlag = 0 
WHERE PartId IN (SELECT PartId FROM CategoryTbl WHERE cat = 100)
于 2012-11-07T19:10:44.587 回答
1

只需在 WHERE 子句中使用"IN"而不是运算符或使用以下代码:"="

UPDATE A
    SET aFlag = 0
    From    PartTbl     As  A
    Inner   Join
        CategoryTbl As  B
    On  A.PartId    =   B.PartId
    WHERE B.cat = 100
于 2012-11-07T19:10:46.863 回答
1
UPDATE PartTbl pt SET aFlag = 0 
WHERE exists (
   SELECT PartId FROM CategoryTbl ct 
    WHERE cat = 100 and pt.partId = ct.partId)
于 2012-11-07T19:11:48.550 回答