简体   繁体   English

如何在SQL的行中查找重复项?

[英]How to find duplicates within rows in SQL?

I see lot's of questions and answers about duplicate rows, but mine is different. 我看到很多有关重复行的问题和答案,但我的却有所不同。

I have a table with 15 columns that should be unique with respect to each other, so within a row these 15 fields should all have different values. 我有一个表,该表具有15列,彼此之间应该是唯一的,因此在一行中,这15个字段应全部具有不同的值。

How can I check this, or more precisely, I want to select all the rows that do have one or more duplicate values within those 15 fields. 如何检查这一点,或更准确地说,我想选择在这15个字段中确实具有一个或多个重复值的所有行。

Any pointers? 有指针吗?

You can use a giant where condition: 您可以where情况下使用巨型:

where col1 in (col2, col3, . . . , col15) or
      col2 in (col3, col4, . . ., col15) or
      col14 in (col15)

This assumes that none of the values are NULL . 假设没有一个值是NULL

You should probably fix the data structure. 您可能应该修复数据结构。 The data in the 15 columns should probably be in 15 rows in a junction table. 15列中的数据可能应该在联结表中的15行中。

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

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