SQL Query To Find Duplicate Records

SQL Query To Find Duplicate Records

This is a detailed tutorial of querying duplicate records in a database table. Learn the SQL Query to find out completely or partially duplicate rows.

Duplicate Table Records

There might be cases when you require to find out the duplicate records of a database table. The duplicate records refer to the table rows who are either completely or partially duplicate. Two rows will be considered as completely duplicate if all the columns for both the rows have the same values and if some of the columns have duplicate values for the two rows, then both of them will be considered as partially duplicate. In this tutorial, we’ll find out how you can query partially as well completely duplicate rows.

SQL Query To Find Duplicate Rows

The query syntax is as defined below.

This syntax makes use of the GROUP BY Statement along with the HAVING Clause.


Two different queries given below demonstrates the process of querying duplicate records in a table named test. The screenshot of the entire table records is given below.

SQL TABLE With Duplicate Records

You can clearly see this table contains different sorts of duplicate records.

The query to find completely duplicate rows for this table is written below with the screenshot of the query output. We’ve also used the COUNT function in the queries to find the exact number fo times each duplicate row is actually there in the database table.

SQL Query To Find Completely Duplicate Records

The query to find partially duplicate rows, i.e. the rows only where the column full_name have the same value is written below with the screenshot of the query output as well.

SQL Query To Find Partially Duplicate Records (Duplicate Column Values))

Note. By changing the integer number from 1 to any other number in the HAVING clause, you can query the records that are duplicated a particular number of times.

The following query selects all the columns having the same values for the column full_name and score exactly in 3 table records.

I hope you found this guide useful. If so, do share it with others. If you have any questions related to this article, feel free to ask us in the comments section.

And do not forget to subscribe to WTMatter!

Subscribe To WTMatter!

Receive updates of our latest articles via email. Enter your email address below to get started.

Leave a Reply

Your email address will not be published. Required fields are marked *