如何在SQLite中删除最后10条记录

6
在Sqlite中,我可以知道如何删除最后10条记录吗?我编写了以下代码,但似乎根本不起作用。
delete from tb_news where newsid = (SELECT newsid from tb_news order by newsid asc limit 10)
3个回答

10

你可以使用

 delete from tb_news where newsid IN 
(SELECT newsid from tb_news order by newsid desc limit 10)

1
将您的SQL语句更改为以下内容。
delete from tb_news where newsid IN (SELECT newsid from tb_news order by newsid DESC limit 20)

附注:sqllite可能不支持子查询中的LIMIT。

应该使用 DESC 而不是 ASC。 - Yaqub Ahmad
@YaqubAhmad 我已经更正了答案,感谢您指出。 - Lipongo

0

你试过了吗?

delete from tb_news where newsid IN (SELECT newsid from tb_news order by newsid asc limit 20)

我不知道你的表结构,但也许应该使用 DESC 而不是 ASC。我的意思是 DESC 会给你最大的 ID(因此是最新的)。


应该使用 DESC 而不是 ASC。 - Yaqub Ahmad

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接