I need to delete partially similar rows in a table, using MySQL. Ex:
From table1 (id,color1,color2,key) content:
id,color1,color2,key
-----------------------------
1,Blue,Green,AASDDD
2,Blue,Green,JJUUYYY
3,Blue,Red,HHYYY
4,Green,Red,KKIII
5,Blue,Red,KKIIUUUU
I’d like to delete the duplicate rows in color1,color2 and get:
id,color1,color2,key
-----------------------------
1,Blue,Green,AASDDD
3,Blue,Red,HHYYY
4,Green,Red,KKIII
Something like
delete FROM table1 WHERE Exists(SELECT color1,color2 FROM table1)
What’s the best way to do this in MySQL without creating a temporary table?
(I know there are many posts about deleting duplicate rows in MySQL, but not for partially matching rows.)
edit
MySQL can’t delete from a table with a subquery of the same table. To work around that limitation you can do this: