Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How could I search for duplicates records in a query

Status
Not open for further replies.

hugheskbh

Programmer
Dec 18, 2002
37
US
I have to create a query to search an employee master file for employees that may have the exact same social security number. How can I do this in sql.

Thanks you
 

Qry:

SELECT A.SSN, COUNT(DISTINCT A.SSN) COUNT
FROM EMPLOYEEMASTER A
GROUP BY A.SSN
HAVING COUNT(DISTINCT A.SSN) > 1

Hope this should help you,

Cheers
Venu
 
there are issues if there are more than two duplicates, but this would get you started

select a.SSN ,a.Full_Name, b.Full_Name from Emp_table a,emp_table b where a.SSN =b.SSN and a.rowid <> b.rowid;

to cope with many dupes

Select c.SSN, C.Full_name from emp_table c where c.SSN in (select a.SSN from Emp_table a,emp_table b where a.SSN =b.SSN and a.rowid <> b.rowid);

I tried to remain child-like, all I acheived was childish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top