求一个SQL语句

hexinyu2005 2006-08-18 09:24:22
有一个表A
aid bid cid
1 2 3
2 2 3

表B
aid bid cid
1 2 3
2 2 3
3 2 3

怎么查询出表B在表A中没有的记录,也就是
aid bid cid

3 2 3
...全文
119 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wallsshi 2006-08-18
  • 打赏
  • 举报
回复
aid相同是否就能代表bid,cid也相同?楼主没有说清。
如果可以代表,则tdtjjiao mugua604 i9988 MicrosoftSQL 就可以了
否则得用 liangpei2008 xyxfly的
jerrie_1 2006-08-18
  • 打赏
  • 举报
回复
declare @a table(aid int,bid int,cid int)
insert into @a
select 1,2,3
union all
select 2,2,3

declare @b table(aid int,bid int,cid int)
insert into @b
select 1,2,3
union all
select 2,2,3
union all
select 3,2,3

select * from @a
select * from @b

select * from @b where (cast(aid as varchar)+cast(bid as varchar)+cast(cid as varchar)) not in(select (cast(aid as varchar)+cast(bid as varchar)+cast(cid as varchar)) as comid from @a)

tdtjjiao 2006-08-18
  • 打赏
  • 举报
回复
select * from A
where aid not in(select aid from B)
liangpei2008 2006-08-18
  • 打赏
  • 举报
回复
--表1
DECLARE @T TABLE(AID INT,BID INT,CID INT)
INSERT @T SELECT 1,2,3
UNION ALL SELECT 2,2,3
--表2
DECLARE @T1 TABLE(AID INT,BID INT,CID INT)
INSERT @T1 SELECT 1,2,3
UNION ALL SELECT 2,2,3
UNION ALL SELECT 3,2,3
--查询
SELECT *
FROM @T1 A
WHERE NOT EXISTS
( SELECT 1 FROM @T WHERE AID=A.AID AND BID=A.BID AND CID=A.CID )
xyxfly 2006-08-18
  • 打赏
  • 举报
回复
select * from b where not exits(select * from a where a.aid=b.aid and a.bid=b.bid and a.cid=b.cid)
mugua604 2006-08-18
  • 打赏
  • 举报
回复
select * from A where aid not in(select aid from B)
i9988 2006-08-18
  • 打赏
  • 举报
回复
select b.* from b left join a
on a.aid=b.aid
where b.aid is null

MicrosoftSQL 2006-08-18
  • 打赏
  • 举报
回复
select * from A
where aid not in(select aid from B)

34,594

社区成员

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

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