两个表格,如下所示。
tbl-1
------
userid
teamid
teamname
elimimated
tbl-2
------
teamid
selectedteam
我想更新tbl-1.eliminated = 1如果tbl-2.selectedteam为空?如何在一个sql命令中实现这一点?
答案 0 :(得分:2)
UPDATE tbl-1 SET eliminated=1
WHERE teamid IN (
SELECT t2.teamid FROM tbl-2 AS t2
RIGHT JOIN tbl-1 AS t1
ON t2.teamid = t1.teamid
WHERE t2.selectedteam IS NULL
);