Sqlite how delete last added entry of a table
I'm trying to delete the last added entry of a table:
DELETE FROM notes ORDER BY created_at DESC LIMIT 1
This just causes the following error:
near "ORDER": syntax error
Why might I be getting this error? (notes
exists and has record开发者_Python百科s in it!)
Try this
DELETE FROM notes WHERE id = (SELECT MAX(id) FROM notes);
delete from notes where created_at = ( select max(created_at) from notes );
Watch out, this will not limit the number of rows deleted. If there are more than one row at max(created_at), this will delete all of them because the subject you specified does not exist (last added entry of a table).
精彩评论