itu bisa dilakukan tetapi tidak yakin apakah itu lebih efisien daripada hanya melakukannya di tingkat aplikasi:
meja Anda:
mysql> select * from test;
+----+--------+--------+--------+
| id | field1 | field2 | field3 |
+----+--------+--------+--------+
| 1 | A | B | C |
| 2 | D | E | F |
| 3 | A | H | I |
| 4 | J | K | A |
| 5 | M | D | O |
+----+--------+--------+--------+
5 rows in set (0.00 sec)
pilih untuk menemukan dupes:
mysql> select count(value) as dupe_count,value from (select field1 as value from test union all select field2 from test union all select field3 from test) as tbl group by value having count(value) > 1 order by 1 desc;
+------------+-------+
| dupe_count | value |
+------------+-------+
| 3 | A |
| 2 | D |
+------------+-------+
2 rows in set (0.00 sec)
pada dasarnya Anda menyatukan tiga kolom menjadi satu lalu mencari dupes