SQL数据查询的问题

cryks 2009-06-08 02:15:42
我有两个表
都有一个 相同的列
例子

表一

id cpcode ddup
1 234 223344
2 324 443322
3 432 456477
4 121 436789
5 323 652312
6 453 441188

表二

id ddup
1 223344
2 443322
3 456477


现在要找出 表一中 ddup列的数据 不包含表二ddup的数据的项
结果
把不包含的数据显示出来
4 121 436789
5 323 652312
6 453 441188






...全文
40 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
贾桂权 2009-06-08
  • 打赏
  • 举报
回复
declare @a table(id int, cpcode int, ddup int)
insert @a values(1, 234, 223344)
insert @a values(2, 324, 443322)
insert @a values(3, 432, 456477)
insert @a values(4, 121, 436789)
insert @a values(5, 323, 652312)
insert @a values(6, 453, 441188)

declare @b table(id int, ddup int)
insert @b values(1, 223344)
insert @b values(2, 443322)
insert @b values(3, 456477)

select * from @a a where not exists(select 1 from @b where a.ddup=ddup)
/*
id cpcode ddup
----------- ----------- -----------
4 121 436789
5 323 652312
6 453 441188
*/
ks_reny 2009-06-08
  • 打赏
  • 举报
回复

select * from t1 where not exists (select 1 from t2 where t1.ddup=t2.ddup)
贾桂权 2009-06-08
  • 打赏
  • 举报
回复
select * from a where not exists(select 1 from b where a.ddup=b.ddup)
LangpiMajia 2009-06-08
  • 打赏
  • 举报
回复
select * from 表一 where ddup not in (select ddup from 表二)
JonasFeng 2009-06-08
  • 打赏
  • 举报
回复
SELECT T.* 
FROM 表1 T where ddup not in (select ddup from 表2)

22,294

社区成员

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

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