mySQL的子查询限制
这可能是一个容易的…我怎么能达到我想要的这个查询:
delete from posts where id not in (SELECT id FROM posts order by timestamp desc limit 0, 15)
所以,简而言之,我想删除不是最新的每个post15。
当我尝试查询时,我得到MySQL不支持“LIMIT&IN / ALL / ANY / SOME子查询
编辑
mySQL服务器版本:5.5.8 mySQL客户端版本:mysqlnd 5.0.7-dev - 091210 - $ Revision:304625 $ 错误:#1235 - 此版本的MySQL尚不支持“LIMIT&IN / ALL / ANY / SOME子查询”
尝试这个:
DELETE FROM posts WHERE id not in ( SELECT * FROM ( SELECT id FROM posts ORDER BY timestamp desc limit 0, 15 ) as t);
你可以试试这个:
DELETE p1.* FROM posts p1 INNER JOIN (SELECT id FROM posts ORDER BY timestamp DESC LIMIT 0, 15 ) AS p2 ON p1.id = p2.id;
由于最新的15将始终来自前15名,如果您按降序排列。您可以删除任何没有进入前15名的编号。像这样我只是试了一下,它工作得很好。 希望它可以帮助别人
Delete from `table` where id not in (SELECT * FROM (Select id from `table` order by id desc limit 15) as derivedTable);