---
title: "How to find duplicate values in a SQL table"  
description: "How to find duplicate values in a SQL table"  
author: "Revati S Misra"  
published: 2023-04-12  
updated: 2023-04-17  
canonical: https://www.mindstick.com/forum/157764/how-to-find-duplicate-values-in-a-sql-table  
category: "mssql server"  
tags: ["sql server", "sql"]  
reading_time: 2 minutes  

---

# How to find duplicate values in a SQL table

How to find [duplicate values](https://www.mindstick.com/forum/33504/how-to-find-duplicate-values-in-devexpress-gridview) in a [SQL table](https://www.mindstick.com/forum/160519/how-can-i-update-sql-table-by-dataset-data-in-ado-dot-net)

## Replies

### Reply by Aryan Kumar

SELECT column1, column2, COUNT(*)

FROM Student

GROUP BY column1, column2

HAVING COUNT(*) > 1;\
\
The **HAVING** clause is used to filter the groups based on the count value. In this case, we are only returning the groups where the count value is greater than 1, which indicates that there are duplicate values.

You can modify the column names in the **SELECT** clause and the grouping columns in the **GROUP BY** clause to fit your specific table structure.

### Reply by Krishnapriya Rajeev

To find [duplicate](https://www.mindstick.com/forum/160911/sql-query-to-find-duplicate-records-in-a-table-in-sql-server) [values](https://www.mindstick.com/forum/327/sum-textbox-values) in a [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap), you can use the GROUP BY clause and the HAVING clause.

Here's an example SQL query that finds duplicate values in a table called my_table, where the duplicates are determined by the combination of columns col1 and col2:

```plaintext
SELECT col1, col2, COUNT(*)
FROM my_table
GROUP BY col1, col2
HAVING COUNT(*) > 1;
```

This query groups the rows in *my_table* by combining values in the *col1* and *col2* columns and counts the number of rows in each group. The HAVING clause filters the groups to only those with a count greater than 1, meaning there are duplicate values in the col1 and col2 columns.

You can modify this query to include additional columns in the output or to use different criteria for determining duplicates, depending on the requirements of your specific use case.


---

Original Source: https://www.mindstick.com/forum/157764/how-to-find-duplicate-values-in-a-sql-table

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
