MYSQL delete all results having count(*)=1

后端 未结 3 475
天命终不由人
天命终不由人 2020-12-15 01:19

I have a table taged with two fields sesskey (varchar32 , index) and products (int11), now I have to delete all rows that having group by sesskey count(*) = 1. I\'m trying a

3条回答
  •  有刺的猬
    2020-12-15 02:18

    The SubQuery should work

     Delete from taged 
      Where sesskey in 
         (Select sesskey 
          From taged 
          Group by sesskey 
          Having count(*) = 1)
    

    EDIT: Thanks to @Quassnoi comment below... The above will NOT work in MySql, as MySql restricts referencing the table being updated or deleted from, in a Subquery i you must do the same thing using a Join ...

提交回复
热议问题