如何查询表中的所有重复行

来源:百度知道 编辑:UC知道 时间:2024/06/08 00:48:40
比如A(a1,a2,a3,a4)表中的a1字段有重复,如何用SQL语句查询出a1字段在A表中有重复的所有信息

select * from A where a1 in(select a1 from A group by a1 having count(*)>1)

select from 表名
where 列名 in (select 列名 from 表名 group by stuId having count(列名) > 1)
and 列名 not in (select min(列名) from 表名 group by stuId having count(列名)>1)
表明,列名,你自己去调吧,如果想删除表中重复的,把select 换成delect就行

有主键的话就很简单了,如果没主键,那么在SQLServer2005或以上版本中也很简单!方法的话你Hi我吧,因为具体情况具体分析。