Finding duplicate rows in SQL

Normally we want to fetch this information that which row have duplicate value.So here i am sharing very easy solution for this.by using this query you can get which row have multiple entries.

SELECT surname, 
 COUNT(surname) AS numOftimes
FROM employee
GROUP BY surname
HAVING ( COUNT(surname) > 1 )


You could also use this technique to find rows that occur exactly once or n time:

SELECT surname
FROM employee
GROUP BY surname
HAVING ( COUNT(surname) = 1 )
or for 'n' times


SELECT surname
FROM employee
GROUP BY surname
HAVING ( COUNT(surname) = n )

Vinay

I am an Oracle ACE in Oracle ADF/Webcenter. Sr Java Consultant-working on Java/J2EE/Oracle ADF/Webcenter Portal/ content and Hibernate for several years. I'm an active member of the OTN JDeveloper/Webcenter forum. Passionate about learning new technologies. I am here to share my knowledge. Give your views and suggestion on [email protected] .

More Posts - Website

Follow Me:
TwitterLinkedInGoogle PlusYouTube