Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete last 10 records in sqlite

Tags:

sqlite

In Sqlite, can I know how to delete last 10 records? I've wrote following coding but seems not working at all.

delete from tb_news where newsid = (SELECT newsid from tb_news order by newsid asc limit 10)
like image 265
PPShein Avatar asked Oct 05 '12 03:10

PPShein


2 Answers

You can use

 delete from tb_news where newsid IN 
(SELECT newsid from tb_news order by newsid desc limit 10)
like image 170
Yaqub Ahmad Avatar answered Sep 19 '22 13:09

Yaqub Ahmad


Change your SQL statement to the below.

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

Side note: sqllite may not support LIMIT in the sub query.

like image 33
Lipongo Avatar answered Sep 21 '22 13:09

Lipongo