Let’s say you have a column in your table where you want to know whether there are any duplicates in it. You can make use of the SQL DISTINCT command. Here’s how you can do it.
How to find duplicates using SQL
1. SELECT count(columnName) from tableName
2. SELECT count(DISTINCT columnName) from tableName
The first select command counts every row that you have in tableName.
The second select command counts ONLY the distinct value for that column. So for example, if you had 246 “david” in columnName, using the distinct select will only return you 1 count since strictly speaking, there’s only 1 distinct value of “david” in that column.
By comparing the two numbers that you received back from the 2 select statements above (1 minus 2), you will know how many duplicates that you have in that specific column of a table.
Leave a Reply