日期:2014-05-19  浏览次数:20368 次

菜鸟请教:求一SQL语句!!!
数据库中有两张表,结构如下:
表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语句怎么写??

学习,关注……


------解决方案--------------------
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 * from A where A.ID not in (select ID from B)
------解决方案--------------------
Select A.* From A Left Join B On A.ID = B.ID Where B.ID Is Null
------解决方案--------------------
select * from [A] where [id] not in (select [id] from [B])
------解决方案--------------------
--方法一:
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