Nancy thakkar Nancy thakkar - 3 months ago 11
MySQL Question

How to delete last 2 rows from sqlite database table in Android?

I am working on Android app In which I want to delete last two rows from sq-lite database table. If any one knows then please help.

I have implement a query which delete only last row

String deleteQuerry= "DELETE FROM my_chat WHERE project_id ='"
+ project_id
+ "' AND id = (SELECT MAX(id) FROM my_chat)";

Answer

You can use

DELETE FROM my_chat WHERE project_id ='" + project_id + "' AND id in (select id from my_chat order by id desc limit 2)

Reference: How to delete last 10 records in sqlite

Comments