怎样在两个结构相同的表中找出不同的记录(Sql Server 2000)

visual 2001-11-25 07:39:18
例如:
表1

ID 电话号码
01 1111111
02 2222222
03 3333333
04 3332222
表2
ID 电话号码
01 1111111
02 2222222

结果: 将03,04 两条记录找出来
如果各写一个循环,当然是可以,但怎样才能最快的找出来,最好SQL语句。

...全文
55 3 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
visual 2001-11-25
  • 打赏
  • 举报
回复
谢谢。
nononono 2001-11-25
  • 打赏
  • 举报
回复

select ID from 表1 where ID not in (select ID from 表2)
union
select ID from 表2 where ID not in (select ID from 表1)

nononono 2001-11-25
  • 打赏
  • 举报
回复
select ID from 表1 where not exist(select * from 表2 where 表1.ID=表2.ID)
union
select ID from 表2 where not exist(select * from 表1 where 表2.ID=表1.ID)

相关推荐
发帖
MS-SQL Server

3.4w+

社区成员

MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
帖子事件
创建了帖子
2001-11-25 07:39
社区公告
暂无公告