如何删除MySQL中的SELECT?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (83)

此代码不适用于mysql 5.0,如何重写它以使其工作。

DELETE FROM posts where id=(SELECT id FROM posts GROUP BY id  HAVING ( COUNT(id) > 1 ))

我想删除没有唯一ID的列。我要补充的是,大多数情况下,它只有一个id(我尝试了in语法,但它也不起作用)。

提问于
用户回答回答于
DELETE FROM posts WHERE id IN (
    SELECT * FROM (
        SELECT id FROM posts GROUP BY id HAVING ( COUNT(id) > 1 )
    ) AS p
)
用户回答回答于
DELETE 
  p1
  FROM posts AS p1 
CROSS JOIN (
  SELECT ID FROM posts GROUP BY id HAVING COUNT(id) > 1
) AS p2
USING (id)

扫码关注云+社区

领取腾讯云代金券