Keep only N last records in SQLite database, sorted by date
问题 I have an SQLite database that I need to do the following: Keep only last N records, sorted by date. How do you do that? 回答1: To delete all but the latest 10 records. delete from test where id not in ( select id from test order by date desc limit 10 ) 回答2: According to the SQLite documentation: If SQLite is compiled with the SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option, then the syntax of the DELETE statement is extended by the addition of optional ORDER BY and LIMIT clauses. (...)