日期:2014-05-18  浏览次数:20824 次

如何写一个SQL语句,选出表1中不含表2的ID,得到结果的记录?
表1:
id         name         age
1             aa             15
2             bb             16
3             cc             17
4             dd             18

表2:
id
2
3

结果:
id         name         age
1             aa             15
4             dd             18

如何写一个SQL语句,选出表1中不含表2的ID,得到结果的记录?



------解决方案--------------------
select * from tb1 where not exists(select 1 from tb2 where tb2.id = tb1.id)
------解决方案--------------------
Select A.* From 表1 A Where id Not In (Select id From 表2)
------解决方案--------------------
Select A.* From 表1 A Where Not Exists(Select id From 表2 Where id = A.id)
------解决方案--------------------
select * from 表1 where id not in(select id from 表2)