Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table with different fields like firstname, lastname, DOB, EmpID , State ,City

now i need to get the records who have same firstname, lastname and DOB.

please help.

suppose if two employees have same name and dob i need those records who have same name and DOB
Posted

Something like this can help-
SQL
SELECT E1.Firstname, E1.Lastname, E1.DOB, EmpID , [State] ,City
FROM Employees E1
INNER JOIN 
(
	SELECT Firstname, Lastname, DOB,COUNT(Firstname)
	FROM Employees
	GROUP BY Firstname, Lastname, DOB
	HAVING COUNT(Firstname)>1
) AS E2 
ON E1.Firstname=E2.Firstname AND E1.Lastname=E2.Lastname AND E1.DOB=E2.DOB
--ORDER BY  E1.Firstname, E1.Lastname, E1.DOB, EmpID 


In case, you need further help please let me know.

Hope, it helps :)
 
Share this answer
 
v2
Comments
saikartik 7-Jul-15 7:50am    
thank u
Suvendu Shekhar Giri 7-Jul-15 7:55am    
Glad to know that it helped :)
Try:
SQL
SELECT FirstName, LastName, DOB
FROM MyTable
GROUP BY FirstName, LastName, DOB
HAVING COUNT(FirstName) > 1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900