如何筛选出两个表之间的区别?

yiyiwenwen1211 2014-02-24 08:02:36
table1:
id name
1 123
2 456
3 678
4 547
5 123
6 999


table2:
id name
1 564
2 123
3 456
4 100


我想选出table2中没在table1中出现过的字段值,谢谢各位了

result:
id name
1 564
2 100
...全文
66 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
中国风 2014-02-24
  • 打赏
  • 举报
回复
--id\name在表2同时存在时不出现 select * from table1 as a where not exists(select 1 from table2 where id=a.id and name=a.name)
专注or全面 2014-02-24
  • 打赏
  • 举报
回复


  select id,Name from table2
    except
  select id,Name from table1


哥眼神纯洁不 2014-02-24
  • 打赏
  • 举报
回复
select * from table2 where name not in(select name from table1)

34,590

社区成员

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

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