我想将一个内部联接的表更新到另一个表,但是应该更新的行应该具有特定条件或者不存在于第二个表中:
Update T1
Set STATUS = 'R'
From table1 T1
inner join table2 T2
on T1.ID = T2.ID and T2.STATUS = 'F'
Update T1
Set STATUS = 'R'
From table1 T1
Where T1.ID not exists in(Select T2.ID from table2 T2)
如何通过一个查询来编写它?
答案 0 :(得分:0)
您可以在where子句中执行OR。如下所示:
Update T1 Set STATUS = 'R' From table1 T1 inner join table2 T2 on T1.ID = T2.ID and T2.STATUS = 'F' or T1.ID not exists in(Select T2.ID from table2 T2)