[英]How to set one table's field based on value in another table
I have two tables. 我有两张桌子。 The first contains a list of ID's.
第一个包含ID列表。 The second has a larger list of ID's.
第二个具有更大的ID列表。 I want to update the second table ONLY if it doesn't exist in the first.
我只想更新第二张表中的第二张表。 This isn't catching all of them:
这并没有抓住所有人:
UPDATE TableB
LEFT OUTER JOIN TableA
ON TableB.id = TableA.id
SET TableB.Status = "Inactive"
WHERE TableB.id IS NULL;
You are close, assuming that TableB
is the "second" table: 您很接近,假设
TableB
是“第二”表:
UPDATE TableB b LEFT OUTER JOIN
TableA a
ON b.id = a.id
SET b.Status = 'Inactive'
WHERE a.id IS NULL;
------^
Your WHERE
clause referenced the wrong table. 您的
WHERE
子句引用了错误的表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.