How to delete first few records from a table using SQLite query?

sqlite

Solution

I gather you want to maintain 100 rows in your table by removing the first 'X' rows every time your table grows beyond 100 rows. Here is what you can do:

Delete from table_name where rowid IN (Select rowid from table_name limit X);

This will keep removing the first 'X' rows as and when your SQLite table grows.

Problem

I want to delete first 10 records(i.e. records 1 to 10) from my table in SQLite if the record count is 110. Only 100 records I want in my table. If record count is more than 100 then those records should be deleted, as a result if I add new records then also only 100 records should be present. How could it be possible using SQLite query, please provide your suggestions. Thanks.

Original source