求一两表对比查询语句

KK_LIU 2009-09-05 10:13:24
系统环境:W2k+SQL2000
表A:Name,Age,Time
表B:Name,Tel,Age,Score,Bg,Address
表A有10万记录,表B有上百万记录,均以Name,Age两字段标识唯一记录。
现要查出表A中还没录入表B的记录,这SQL该怎么写?
...全文
146 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
KK_LIU 2009-09-07
  • 打赏
  • 举报
回复
谢谢大家,可以了,虽然不知是不是最好的效率,交完差再作研究...
dawugui 2009-09-06
  • 打赏
  • 举报
回复
[Quote=引用楼主 kk_liu 的回复:]
系统环境:W2k+SQL2000
表A:Name,Age,Time
表B:Name,Tel,Age,Score,Bg,Address
表A有10万记录,表B有上百万记录,均以Name,Age两字段标识唯一记录。
现要查出表A中还没录入表B的记录,这SQL该怎么写?
[/Quote]
select a.* from a where not exists(select 1 from b where name = a.name and age = a.age)
ChinaITOldMan 2009-09-06
  • 打赏
  • 举报
回复
select * from a
where not exists(select 1 from b where a.name=b.name and a.age=b.age)
lihan6415151528 2009-09-06
  • 打赏
  • 举报
回复

select
*
from
a
where
not exists(select 1 from b where a.name=b.name and a.age=b.age)
fanzhouqi 2009-09-06
  • 打赏
  • 举报
回复
select
*
from a
left join b
on a.name=b.name
where b.name is null
jack_ailly 2009-09-06
  • 打赏
  • 举报
回复
SQL 2005:
select name,age from a
except
select name,age from b
邹夫子 2009-09-06
  • 打赏
  • 举报
回复

select * from b
where not exists(select 1 from a where a.name=b.name and a.age=b.age)


不要搞反了A、B的顺序
flylovejings 2009-09-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 jack_ailly 的回复:]
SQL 2005:
SQL codeselect name,agefrom aexceptselect name,agefrom b
[/Quote]


不理解except关键字

关注下
邹夫子 2009-09-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 jack_ailly 的回复:]
SQL 2005:
SQL codeselect name,agefrom aexceptselect name,agefrom b
[/Quote]

测试了一下,好像只有七楼的可以

guoli0813 2009-09-06
  • 打赏
  • 举报
回复
ding
十八道胡同 2009-09-06
  • 打赏
  • 举报
回复

select * from a
where not exists (select 1 from b where a.name=b.name and a.age=b.age)
jiannye 2009-09-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 herowang 的回复:]
select * from a
where not exists(select 1 from b where a.name=b.name and a.age=b.age)
[/Quote]

跟一楼的没什么区别吗
黄_瓜 2009-09-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 herowang 的回复:]
select * from a
where not exists(select 1 from b where a.name=b.name and a.age=b.age)
[/Quote]
多打几个字就跑你后面去了 O(∩_∩)O~
黄_瓜 2009-09-05
  • 打赏
  • 举报
回复
select * from a 
where not exists(select 1 from b where a.name=b.name and a.age=b.age)

不知道是不是最高效的
--小F-- 2009-09-05
  • 打赏
  • 举报
回复
select 
*
from
a
where
not exists(select 1 from b where a.name=b.name and a.age=b.age)
  • 打赏
  • 举报
回复
select * from a
where not exists(select 1 from b where a.name=b.name and a.age=b.age)
华夏小卒 2009-09-05
  • 打赏
  • 举报
回复

select * from A
where exists (select 1 from b where a.name<>b.name and a.age<>b.age)

34,590

社区成员

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

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