同一个表中,如何写SQL语句查找某一字段重复的记录?

2024年11月09日 16:01
有5个网友回答
网友(1):

个人认为单纯的使用SQL语句来实现是非常困难的。可以使用据体的某种语言(c,c#,java,.net)等来辅助实现此种功能。

网友(2):

查询C字段有重复的记录吗?
如果是小表可以这样写:
select a from tabname
where c in
(select c from tabname group by c having count(1) >1 )
大表(需建c列索引):
select a from tabname a
where exists (select c from tabname b where b.c=a.c group by c having count(1) >1 )

网友(3):

SELECT * FROM tab WHERE C in (
SELECT C
FROM tab
GROUP BY C
HAVING COUNT(A) > 1 )

网友(4):

select A from 表
group by A
having count(C)>=2

网友(5):

select A FROM 表
where C in (
SELECT C FROM 表
group by C
having count(C)>1)