代码之家  ›  专栏  ›  技术社区  ›  JLLMNCHR

SQL选择表A中但不在表B中的记录

  •  -1
  • JLLMNCHR  · 技术社区  · 3 年前

    请,有人能帮我找到

    (在DB2中)

    1 回复  |  直到 3 年前
        1
  •  0
  •   jarlh    3 年前

    你可以简单地使用 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)
    
        2
  •  0
  •   pooja    3 年前

    其中,表_B.field_1=表_A.field_1