简体   繁体   English

SQL - 如何 select 行具有相同的 ID 值,其中所有其他列值也相同

[英]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.我需要 select 所有具有相同 ID的行和所有其他列值也必须相同 This table consists of 20 columns.该表由 20 列组成。

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相应地更改 group by 和 where 条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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