简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM