如何查询同一个表中两个字段分别相同的数据

jlds0123 2008-08-25 02:34:53
表X
id B C D

0 2 3 4

1 6 7 8

2 2 8 4


第一条和第四条数据 B、D字段值相同,如何将其查出来 (详细说明下,谢谢)
...全文
1392 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
忆轩辕 2008-08-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 roy_88 的回复:]
select * from table1 t where (select count(1) from table1 where b=t.b and d=b.d)>1
[/Quote]
feng2112 2008-08-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 roy_88 的回复:]
select * from table1 t where (select count(1) from table1 where b=t.b and d=b.d)>1
[/Quote]
rhq12345 2008-08-25
  • 打赏
  • 举报
回复

select a.B,a.D from x a, x b where a.B=b.B and a.D=b.D
sp4 2008-08-25
  • 打赏
  • 举报
回复

--如果想直接排列出顺序,便于查看就加上排序
select * from table_Pqs Pqs
where Exists(select 1 from table_Pqs
where b=Pqs.b and d=Pqs.d And id<>table_Pqs.id)
Order By b,d

--如果作为一条记录显示 那就如上用inner join方式,但就结果而言应该是反复出现了2次
sp4 2008-08-25
  • 打赏
  • 举报
回复


select * from table_Pqs Pqs
where Exists(select 1 from table_Pqs
where b=Pqs.b and d=Pqs.d And id<>table_Pqs.id)

Humming-bird 2008-08-25
  • 打赏
  • 举报
回复
select * from test a, test b where a.B=b.B and a.D=b.D and a.ID<>b.ID
水族杰纶 2008-08-25
  • 打赏
  • 举报
回复
declare @t table(id int, B int, C int, D int)
insert @t select 0, 2, 3, 4
insert @t select 1, 6, 7, 8
insert @t select 2, 2, 8, 4
select * from @t t where exists(select 1 from @t where B=t.B and D=t.D and ID<>t.ID )
liyan93834183 2008-08-25
  • 打赏
  • 举报
回复
select * from x where b in (select b from x) and d in (select d from x)
sxn19811006 2008-08-25
  • 打赏
  • 举报
回复
自连接、同一个表建两个别名
flairsky 2008-08-25
  • 打赏
  • 举报
回复
select a.* from x a inner join x b on a.b = b.b and a.d=b.d
中国风 2008-08-25
  • 打赏
  • 举报
回复
select * from table1 t where (select count(1) from table1 where b=t.b and d=b.d)>1
sxn19811006 2008-08-25
  • 打赏
  • 举报
回复
select a.B,a.D from x a, x b where a.B=b.B and a.D=b.D

34,838

社区成员

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

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