多表关联查询问题,求答?

meimengchengzhen 2006-12-25 01:48:29
例如:
表A NO name
1 a
2 b
3 c
4 d
表B NO name
3 c
现在要查询出结果:
表A NO name
1 a
2 b
4 d
现在一个关键的问题是,我不知道表B中的内容(比方说表B中可能还有2,b等等情况)。
求,如何实现这样的查询,是否可以实现这样的查询??
...全文
153 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
meimengchengzhen 2006-12-25
  • 打赏
  • 举报
回复
谢谢大家~
中国风 2006-12-25
  • 打赏
  • 举报
回复
用判断真假的方法,效率高
select * from 表A a where not exists
(select 1 from 表B where NO=a.NO and name=a.name )
sgucxc0 2006-12-25
  • 打赏
  • 举报
回复

declare @ta table(No int,name varchar(8))
insert into @ta select 1,'a' union select 2,'b' union select 3,'c' union select 4,'d'

declare @tb table(No int,name varchar(8))
insert into @tb select 2,'b' union select 3,'c'

select a.* from @ta a where a.no not in(select no from @tb) and a.name not in(select name from @tb)
/*结果

No name
----------- --------
1 a
4 d

(所影响的行数为 2 行)
*/
caixia615 2006-12-25
  • 打赏
  • 举报
回复
select * from A where not exists(select * from B)

34,575

社区成员

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

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