将SELECT语句更改为DELETE

时间:2013-10-06 11:16:07

标签: mysql sql

在我的表中有很多重复的行。我有一个SELECT,提供我想要删除的数据,但我该怎么做?无论我尝试什么,我都会收到错误。

SELECT *
  FROM tablename t
 WHERE NOT EXISTS (         
              SELECT 1
                FROM tablename t2
               WHERE t2.column = t.column
              HAVING COUNT(*) = 1
                     )

1 个答案:

答案 0 :(得分:0)

只需将'SELECT *'更改为'DELETE'

即可
DELETE 
FROM tablename t
WHERE NOT EXISTS (         
              SELECT 1
              FROM tablename t2
              WHERE t2.column = t.column
              HAVING COUNT(*) = 1
              )