Sqlite how delete last added entry of a table

Markus picture Markus · Nov 3, 2010 · Viewed 9.3k times · Source

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 records in it!)

Answer

srinathhs picture srinathhs · Nov 3, 2010

Try this

DELETE FROM notes WHERE id = (SELECT MAX(id) FROM notes);