查询表中某列字段有重复的纪录?

jshecn 2005-06-17 03:17:39
今天突然遇到这个问题,不知道怎么写?请大家帮忙
...全文
100 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jshecn 2005-06-17
  • 打赏
  • 举报
回复
不是找出不同的纪录,而是把某个字段重复的纪录给找出来
jshecn 2005-06-17
  • 打赏
  • 举报
回复
谢谢。
wscft 2005-06-17
  • 打赏
  • 举报
回复
select distinct a.*
from table1 a, table1 b
where b.col1!= a.col1 and b.col2 = a.col2
hxq987 2005-06-17
  • 打赏
  • 举报
回复
学习
wangdehao 2005-06-17
  • 打赏
  • 举报
回复
select * from table where 字段 in (select 字段 from table group by 字段 having count(1)>1 )

or

select *
from table a
where (select count(*) from 表 where 字段=a.字段)>1
hsj20041004 2005-06-17
  • 打赏
  • 举报
回复

---你查一下字段重复的记录,然后再想办法(删除或修改)
select 字段,count(*) as 次数 from tablename group by 字段 having count(*)>1
phantomMan 2005-06-17
  • 打赏
  • 举报
回复
distinct:

select distinct columnname from tablename
lsxaa 2005-06-17
  • 打赏
  • 举报
回复
select *
from 表 a
where (select count(*) from 表 where 某字段=a.某字段)>1

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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