在Sqlite中,我可以知道如何删除最后10条记录吗?我编写了以下代码,但似乎根本不起作用。
delete from tb_news where newsid = (SELECT newsid from tb_news order by newsid asc limit 10)
delete from tb_news where newsid = (SELECT newsid from tb_news order by newsid asc limit 10)
你可以使用
delete from tb_news where newsid IN
(SELECT newsid from tb_news order by newsid desc limit 10)
delete from tb_news where newsid IN (SELECT newsid from tb_news order by newsid DESC limit 20)
你试过了吗?
delete from tb_news where newsid IN (SELECT newsid from tb_news order by newsid asc limit 20)
我不知道你的表结构,但也许应该使用 DESC 而不是 ASC。我的意思是 DESC 会给你最大的 ID(因此是最新的)。