Tuesday, November 22, 2016

Simple SQL Queries to find duplicate record from table.

Here I am discussing about SQL Query to fetch the duplicate record from the database table.

Below query to fetch all record from the table:
SELECT * FROM Employee


Below query to fetch EmployeeName and No of Count that have same EmployeeName:
SELECT EmployeeName,Count(*) FROM Employee Group By EmployeeName

above query fetch all record including having count 1.



Below  query to fetch EmployeeName and No of Count that have same EmployeeName:

SELECT EmployeeName,COUNT(*) AS NoOfEmployee FROM Employee GROUP BY EmployeeName HAVING (COUNT(*)>1)

SELECT EmployeeName,COUNT(EmployeeName) AS NoOfEmployee FROM Employee GROUP BY EmployeeName HAVING (COUNT(EmployeeName)>1)

above query fetch all record including having count greater than 1.

No comments:

Post a Comment