开发者

Sqlite how delete last added entry of a table

开发者 https://www.devze.com 2023-01-23 12:41 出处:网络
I\'m trying to delete the last added entry of a table: DELETE FROM notes ORDER BY created_at DESC LIMIT 1

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号