Home > OS >  SQL - How to select rows with the same ID values where all other column values are also identical
SQL - How to select rows with the same ID values where all other column values are also identical

Time:09-09

I cannot find the answer to the abovementioned problem in the title.

I need to select all rows that have the identical ID and all other column values must also be identical as well. This table consists of 20 columns.

Any suggestion would be much appreciated! Many thanks.

CodePudding user response:

How about this

select id, name, ...other fields
from my_table
where id in (
    Select id, count(id)
    from my_table
    group by id, name, ...other fields
    having count(id) > 1
)

Change group by and where conditions accordingly

  • Related