Skip to content
Advertisement

Return boolean if duplicates exist

How do I return True if a table has any duplicate records and False if it has none.

I don’t need a count, I don’t need to know which rows, all I want to know is if this table has duplicates or not. That’s it.

Advertisement

Answer

If you don’t want to list out columns, then here is one method:

If you have a primary key, then a more efficient method would be:

A relatively efficient method with a primary key would be:

The ? is for the column/columns that you care about in terms of duplicates.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement