两个相同结果集求差值问题

zblaoshu1979 2005-12-01 09:18:13
两个相同的结果集:(id1和id2联合主键)
结果集一:
id1 id2 name
1 1 aaa
1 2 bbb
2 1 dfsd
2 2 uefue
2 3 kjkk
结果集二:
id1 id2 name
1 1 aaa
2 1 dfsd

得到这样结果:
id1 id2 name
1 2 bbb
2 2 uefue
2 3 kjkk
...全文
245 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
常飞梦 2005-12-16
  • 打赏
  • 举报
回复
mark
hglhyy 2005-12-01
  • 打赏
  • 举报
回复
select *
from 结果集1 a
where not exists(select * from 结果集2 b where a.id1=b.id1 and a.id2=b.id2)

UP
liuyulei 2005-12-01
  • 打赏
  • 举报
回复
select * from a
where name not in(select name from b )
liuyulei 2005-12-01
  • 打赏
  • 举报
回复
select a.id1,a.id2,a.name from a left join b
on a.id1=b.id1 and a.id2=b.id2
where b.id1 is null and b.id2 is null
OracleRoob 2005-12-01
  • 打赏
  • 举报
回复
select A.*
from 结果集1 A left join 结果集2 B on A.id1 = B.id1 and A.id2 = B.id2
where B.id1 is null
churchatp1 2005-12-01
  • 打赏
  • 举报
回复
select *
from 结果集1 a
where not exists(select * from 结果集2 b where a.id1=b.id1 and a.id2=b.id2)
常飞梦 2005-12-01
  • 打赏
  • 举报
回复
select t1.id1,t1.id2,t1.name from t1 left join t2 on t1.id1=t2.id1 and t1.id2=t2.id2
where t2.id1 is null

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧