det er muligt, men ikke sikker på, om det er mere effektivt end blot at gøre det på applikationsniveau:
dit bord:
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)
vælg for at finde duper:
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)
dybest set samler du de tre kolonner i én, og leder derefter efter duper