het is te doen, maar weet niet zeker of het efficiënter is dan het alleen op applicatieniveau te doen:
uw tafel:
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)
selecteer om dupes te vinden:
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)
in feite verenig je de drie kolommen tot één en zoek je naar dupes