timw07
timw07

Reputation: 339

SQL inner join UPDATE Query Across tables?

Two tables, as below.

tbl-1
------
userid
teamid
teamname
elimimated


tbl-2
------
teamid
selectedteam

I want to update tbl-1.eliminated = 1 IF tbl-2.selectedteam is null? How can I achieve this in one sql command?

Upvotes: 0

Views: 59

Answers (1)

jbihan
jbihan

Reputation: 3099

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
               );    

Upvotes: 2

Related Questions