请帮忙写出该条件的SQL语句

prettyBoy2002 2003-08-19 09:16:21
有两个表他们结构一样,如A(nodekey,name,bz)和B(nodekey,name,bz)
A表中nodekey和name为主键,B表中也是nodekey和name为主键。
写出SQL语句,检索出在B表中存在而在A表中不存在的记录集。

如写不出,用ADO记录集的方式也行。
...全文
87 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
amtyuranus 2003-08-20
  • 打赏
  • 举报
回复
用not in 或exists就可以了
CrazyFor 2003-08-20
  • 打赏
  • 举报
回复
select * from B表 where not exists(select 1 from A表 where nodekey=B表.nodekey and name=B表.name)


OR:

select b.* from B表 b left join A表 a on a.nodekey=b.nodekey and a.name=b.name
where a.nodekey is null
z5wjz 2003-08-20
  • 打赏
  • 举报
回复
同意楼上各位大虾的意见.
ysycrazy 2003-08-20
  • 打赏
  • 举报
回复
select * from B表 where not exists(select 1 from A表 where nodekey=B表.nodekey and name=B表.name)
伍子V5 2003-08-20
  • 打赏
  • 举报
回复
select * from B表 where not exists(select 1 from A表 where nodekey=B表.nodekey and name=B表.name)
txlicenhe 2003-08-20
  • 打赏
  • 举报
回复
select * from B表 where not exists(select 1 from A表 where nodekey=B表.nodekey and name=B表.name)
zjcxc 2003-08-20
  • 打赏
  • 举报
回复
有两个表他们结构一样,如A(nodekey,name,bz)和B(nodekey,name,bz)
A表中nodekey和name为主键,B表中也是nodekey和name为主键。
写出SQL语句,检索出在B表中存在而在A表中不存在的记录集。



select * from B where not exists(select 1 from A where nodekey=b.nodekey and name=b.name)
dingzhaofeng 2003-08-20
  • 打赏
  • 举报
回复
mark!
lhd_cn 2003-08-20
  • 打赏
  • 举报
回复
up
hjb111 2003-08-19
  • 打赏
  • 举报
回复
select B.* from TableA A,TableB B Where A.nodekey<>B.nodekey
pengdali 2003-08-19
  • 打赏
  • 举报
回复
select * from B表 where not exists(select 1 from A表 where nodekey=B表.nodekey and name=B表.name)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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