how to delete duplicates in mysql using case
Posted
by JPro
on Stack Overflow
See other posts from Stack Overflow
or by JPro
Published on 2010-03-18T10:28:59Z
Indexed on
2010/03/18
10:31 UTC
Read the original article
Hit count: 483
mysql
|mysql-query
Right now I am using something like this to delete duplicates in mysql table :
delete t2 from my_table1 as t1, my_table1 as t2 where
t1.TestCase = t2.TestCase and t2.id > t1.id;
say I have a structure like this :
ID TestCAse Result
1 T1 PASS
2 T2 FAIL
3 T3 FAIL
4 T3 PASS
now, in the above case T3
is duplicate entry, and if I use the SQL that I mentioned above, it would delete 4th row where the result is PASS
, but this is the row that I want to keep and I want row 3 to get deleted which is FAIL
.
Any help please?
Thank you.
© Stack Overflow or respective owner