请教啊,查询A表中未曾出现在B表和C表中的记录,sql2000

sdmc01 2012-08-21 09:34:25
请用sql2000,另外数据记录有5万条以上,请尽量效率高,谢谢
A表

id
001
002
003
004
005
006

B表

002
003
005

C表

003
004
005

查询结果
001
006
...全文
89 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdmc01 2012-08-29
  • 打赏
  • 举报
回复
谢谢各位的帮忙
xiaosa_21 2012-08-22
  • 打赏
  • 举报
回复

declare @t1 table (id int)
insert into @t1
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6

--> 测试数据: @t2
declare @t2 table (id int)
insert into @t2
select 1


--> 测试数据: @t3
declare @t3 table (id int)
insert into @t3
select 3

select * from @t1
except
(select * from @t2
union
select * from @t3)
孤独加百列 2012-08-21
  • 打赏
  • 举报
回复

SELECT * FROM A
WHERE NOT EXISTS
(
SELECT 1 FROM (
SELECT * FROM B
UNION
SELECT * FROM C) AS D WHERE A.id = D.id
)
筱筱澄 2012-08-21
  • 打赏
  • 举报
回复

--1
select * from a
where not exists(select 1 from b where b.id=a.id)
and not exists(select 1 from c where c.id=a.id)
ws_hgo 2012-08-21
  • 打赏
  • 举报
回复
select * from A
where not exists
(
select * from B where A.id = id
)
and
not exists
(
select * from C where A.id = id
)

27,579

社区成员

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

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