I have written this query for getting the employees with same SSN numbers. But this query is giving me the all the employess, can't figure out whats wrong with it.
SELECT a.empid,
a.NAME,
a.ssn
FROM p_data a
WHERE ssn IN (SELECT ssn
FROM p_data b
WHERE b.ssn = a.ssn
GROUP BY ssn
HAVING ( a.ssn ) > 1);
You want groups with more than one record(duplicates), so use
instead of
Another approach which should be more efficient:
This also works if
SSN
is nullable. Then you just have to change the last line to: