Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update last row in sqlite android

I'm trying to make a query that updates the last row in my table. here is the query I'm using:

String updateQuery = "Update table set col = '"+ bla +"' where id=SELECT max(id)";

but this gives mean error..I know how to update last row in SQL but I can't figure it out in SQLITE. What am I missing?

like image 826
Rares Biris Avatar asked Jan 29 '26 22:01

Rares Biris


1 Answers

try one of the two options

Option 1

UPDATE table set col = 1 WHERE id = (SELECT MAX(id) FROM table)

Option 2

Split it in two seperate queries. in first make select to take max id, in second update the value using id as a variable

The second option will work for 100%, I'm not sure the first but it should

like image 141
Fixus Avatar answered Jan 31 '26 13:01

Fixus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!