数据库中有两张表,结构如下:
表A:
ID    Date          ……
001   2005-01-01    ……
002   2005-01-03    ……
003   2005-01-15    ……
……表B:
ID    Name      ……
002   XX        ……
003   YY        ……
004   ZZ        ……
……现在想要得到如下数据:
根据ID判断,筛选出表A中存在且表B中不存在的所有表A中的记录。
请问:这样的SQL语句怎么写??学习,关注……

解决方案 »

  1.   

    Select * From A Where ID Not In (Select ID From B)
      

  2.   

    Select * From A Where Not Exists (Select ID From B Where ID = A.ID)
      

  3.   

    select * from A where A.ID not in (select ID from B)
      

  4.   

    Select A.* From A Left Join B On A.ID = B.ID Where B.ID Is Null
      

  5.   

    select * from [A] where [id] not in (select [id] from [B])
      

  6.   

    --方法一:
    Select * From A Where ID Not In (Select ID From B)
    --方法二:
    Select * From A Where Not Exists (Select ID From B Where ID = A.ID)
    --方法三:
    Select A.* From A Left Join B On A.ID = B.ID Where B.ID Is Null