首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-01-30 
如何写一个SQL语句,选出表1中不含表2的ID,得到结果的记录?表1:idnameage1aa152bb163cc174dd18表2:id23结果

如何写一个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)

热点排行