---
title: "SQL Query to Find Duplicate Records in a Table in SQL Server"  
description: "SQL Query to Find Duplicate Records in a Table in SQL Server"  
author: "Anubhav Sharma"  
published: 2024-07-15  
updated: 2024-07-16  
canonical: https://www.mindstick.com/forum/160911/sql-query-to-find-duplicate-records-in-a-table-in-sql-server  
category: "SQL Server"  
tags: ["database", "sql server", "sql server 2008", "sql server 2012", "sql server 2022"]  
reading_time: 2 minutes  

---

# SQL Query to Find Duplicate Records in a Table in SQL Server

Hi,

I need a [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) to find all duplicate records in my `Employee` [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) based on the `EmployeeID` and `Email` columns. Any [suggestions](https://www.mindstick.com/blog/299486/how-to-write-for-your-audience)?

## Replies

### Reply by Ravi Vishwakarma

To find [**duplicate records**](https://www.mindstick.com/articles/854/remove-delete-duplicate-records-or-rows-sql-server) in your `Employee` table based on the `EmployeeID` and `Email` columns, you can use a query with the `GROUP BY` and `HAVING` clauses.

Here is an example query to identify duplicates:

```plaintext
SELECT
    EmployeeID,
    Email,
    COUNT(*) AS DuplicateCount
FROM
    Employee
GROUP BY
    EmployeeID,
    Email
HAVING
    COUNT(*) > 1;
```

## Explanation:

- `SELECT EmployeeID, Email, COUNT(*) AS DuplicateCount`: This part of the query selects the `EmployeeID`, `Email`, and a count of how many times each combination appears.
- `FROM Employee`: Specifies the table to query.
- `GROUP BY EmployeeID, Email`: Groups the results by `EmployeeID` and `Email` to aggregate the counts.
- `HAVING COUNT(*) > 1`: Filters the results to include only groups with a count greater than 1, indicating duplicates.

This query will return a list of `EmployeeID` and `Email` combinations with more than one occurrence in the `Employee` table, along with the count of those duplicates.

## Read more

[**How do I use the GROUP BY clause to aggregate data in SQL Server?**](https://www.mindstick.com/forum/160897/how-do-i-use-the-group-by-clause-to-aggregate-data-in-sql-server)

[**Implement row-level security in SQL Server to restrict access to data to users.**](https://www.mindstick.com/forum/160896/implement-row-level-security-in-sql-server-to-restrict-access-to-data-to-users)

[**Protect SQL Server database against SQL injection attacks?**](https://www.mindstick.com/forum/160895/protect-sql-server-database-against-sql-injection-attacks)

[**How do I write CRUD operations to modify data in SQL Server tables?**](https://www.mindstick.com/forum/160899/how-do-i-write-crud-operations-to-modify-data-in-sql-server-tables)


---

Original Source: https://www.mindstick.com/forum/160911/sql-query-to-find-duplicate-records-in-a-table-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
