October 29, 2008 at 1:21 pm
Hi,
I have a table called EMPLOYEE which includes the following fields -
EmpNo EmpFName EmpLName Dept Section Phone
001 David Moore Office A 1234
002 Jhon Davies Kitchen A 2345
001 David Moore Office A 3456
003 Sarah White Office A 6789
How can I query the duplicate records from EMPLOYEE table?
I want the result in
EmpNo EmpFName EmpLName Dept Section Duplicate
001 David Moore Office A 2
I don't care about the Phone number is difference.
Anybody know how to write a query?
Thanks.
October 29, 2008 at 2:00 pm
GROUP BY?
in SQL 2005 and above, ROW_NUMBER can be used as well
SELECT
EmpNo
,EmpFName
,EmpLName
,Dept
,Section
,Duplicate = COUNT(1)
FROM Employee
HAVING COUNT(1) > 1 -- to only show duplicates. Comment this out will show everybody
October 29, 2008 at 2:48 pm
Thanks Jerry.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply