请教,SQL语句:查询A表中字段a,b在B表中字段a,b没有出现的所有记录!

dezwen 2008-07-30 10:54:49
请教,SQL语句:查询A表中字段a,b在B表中字段a,b没有出现的所有记录!

表A
a | b | c
1 1 1
1 2 2
2 1 3

表B
a | b | c
1 1 1
1 2 2

我想得到的结果是:
a | b | c
2 1 3
...全文
255 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hyqwan11112 2008-07-31
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 roy_88 的回复:]
SQL codeselect*fromawherechecksum(a,b)notin(selectchecksum(a,b)fromb )
[/Quote]
水族杰纶 2008-07-31
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hery2002 的回复:]
SQL code-->生成测试数据

declare @A table([a] int,[b] int,[c] int)
Insert @A
select 1,1,1 union all
select 1,2,2 union all
select 2,1,3
--Select * from @A

declare @B table([a] int,[b] int,[c] int)
Insert @B
select 1,1,1 union all
select 1,2,2
--Select * from @B

select * from @a a
where not exists (select 1 from @b where [a] = a.[a] and [b] = a.[b])
/*
a b …
[/Quote]
lifeiping 2008-07-31
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20080626/00/43d0d10c-28f1-418d-a05b-663880da278a.html
lb6201883 2008-07-30
  • 打赏
  • 举报
回复


create table A(a int ,b int, c int)



create table B(a int ,b int, c int)

insert A
select 1,1,1 union all
select 1,2,2 union all
select 2,1,3

insert B
select 1,1,1 union all
select 1,2,2

select * from A where not exists(select 1 from B where a=A.a and b=A.b)
中国风 2008-07-30
  • 打赏
  • 举报
回复
select * from a where checksum(a,b) not in(select checksum(a,b) from b )
hery2002 2008-07-30
  • 打赏
  • 举报
回复
-->生成测试数据

declare @A table([a] int,[b] int,[c] int)
Insert @A
select 1,1,1 union all
select 1,2,2 union all
select 2,1,3
--Select * from @A

declare @B table([a] int,[b] int,[c] int)
Insert @B
select 1,1,1 union all
select 1,2,2
--Select * from @B

select * from @a a
where not exists (select 1 from @b where [a] = a.[a] and [b] = a.[b])
/*
a b c
----------- ----------- -----------
2 1 3

*/
sdxiong 2008-07-30
  • 打赏
  • 举报
回复
select a.*
from 表A a
left join 表B b on a.a=b.a and a.b=b.b
where b.a is null

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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