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 )