请有人帮我找到选择TABLE_A中所有记录的SQL语句,除了那些FIELD_1、FIELD_2的组合不在TABLE_B中的记录。(In DB2)的数据库
eeq64g8w1#
您可以简单地使用NOT EXISTS:
NOT EXISTS
select * from table_a ta where not exists (select * from table_b tb where tb.field_1 = ta.field_1 and tb.field_2 = ta.field_2)
c7rzv4ha2#
使用不存在:
select * from table_A where not exists (select * from table_B where table_B.field_1 = table_A.field_1 and table_B.field_2 = ta.field_2)
68de4m5k3#
可以使用反联接。例如:
select * from table_a a left join table_b b on b.field_1 = a.field_1 and b.field_2 = a.field_2 where b.field_1 is null
3条答案
按热度按时间eeq64g8w1#
您可以简单地使用
NOT EXISTS
:c7rzv4ha2#
使用不存在:
68de4m5k3#
可以使用反联接。例如: