关于找出重复纪录

Edison621 2005-06-05 12:20:37
数据库表中有纪录完全相同了,怎样找出来?

比如:

id name
--------------
1 zhou
2 wu
2 wu
3 zheng
3 zheng


怎样得到
id name
--------------
2 wu
3 zheng


...全文
136 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Well 2005-06-05
  • 打赏
  • 举报
回复
select * from tablename
where id in
(
select id from tablename
group id
having count(*)>=2
) B
zlp321002 2005-06-05
  • 打赏
  • 举报
回复
--try

Create table Test(id int,name char(8))
insert into test select 1,'zhou'
union all select 2,'wu'
union all select 2,'wu'
union all select 3,'zheng'
union all select 3,'zheng'

select id,name from test group by id,name having count(id)>1

id name
----------- --------
2 wu
3 zheng

(所影响的行数为 2 行)




daishengs 2005-06-05
  • 打赏
  • 举报
回复
select distinct * from mytable where count(id)>1
yifan600 2005-06-05
  • 打赏
  • 举报
回复
select distinct * from mytable where count(id)>1
ziping 2005-06-05
  • 打赏
  • 举报
回复
select * from table where id in (select min(id) from table gorup by name)
uuxiaoli 2005-06-05
  • 打赏
  • 举报
回复

select id,name from table group by id,name having count(id)>1
Wonny 2005-06-05
  • 打赏
  • 举报
回复
select …… having …… group by ……
自己试试看。
sandwich1981 2005-06-05
  • 打赏
  • 举报
回复
select distinct * from table
daview 2005-06-05
  • 打赏
  • 举报
回复
看你的数据库是怎么定义的。如果是以ID为准:

select * from mytable where count(id)>1

如果以name为准,则:

select * from mytable where count(name)>1

如果以name和id为准就麻烦点。

34,593

社区成员

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

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