how to delete duplicates in mysql using case

前端 未结 1 1410
有刺的猬
有刺的猬 2021-01-24 03:07

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 an         


        
1条回答
  •  时光说笑
    2021-01-24 03:48

    if I undersstand correctly in case of duplicate you want to delete the "FAIL" and not the "PASS" ? in this case you can have the following query:

    delete t2 from my_table1 as t1, my_table1 as t2 where
    t1.TestCase = t2.TestCase and t2.id != t1.id and t2.Result='FAIL'; 
    

    but what do you want to do when all the duplicate have "FAIL" in their column result? With the query above, both will be removed. Do you want to keep one in this case ?

    0 讨论(0)
提交回复
热议问题