Skip to content
Advertisement

Select rows based on duplicates in a column

I want to find all duplicates in a column and display the primary key so I can clean them up.

So after a bunch of tutorials I have this which is supposed to work and returns no rows which is great because it means there’s nothing I need to clean up. ‘equipment_id’ is the primary key on the table

But when I just look for the dupes like this without involving the primary key column

I get 900+ results, which is also fine but I need the primary key so I know which ones to edit.

The result I want will look like

Advertisement

Answer

If the first query be returning any records and the equipment_id really be a primary key column, then it must be the case that a single tent_id value is associated with multiple records/multiple equipment_id values. To find this tent_id values, try asserting the distinct count of the equipment_id:

To generate the output you want, you could try:

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