Android Question Help with a query

Alex_197

Well-Known Member
Licensed User
Longtime User
Hi all.

I don't understand what is wrong with this query

B4X:
UPDATE tblClientGivenMedicine_Temp
SET Notes = '555'
where JobDate='12/20/2025' and DrugID=11197
ORDER by Created DESC
LIMIT 1;

I'm getting error
B4X:
Execution finished with errors.
Result: near "ORDER": syntax error
At line 3:
UPDATE tblClientGivenMedicine_Temp
SET Notes = '555'
where JobDate='12/20/2025' and DrugID=11197
ORDER

according to this page https://www.sqlitetutorial.net/sqlite-update/ it's possible

Thanks
 

ilan

Expert
Licensed User
Longtime User
yes i understand what you mean but the sqlite tutorial is misleading and also wrong:



they also give a button and tell you TRY IT and if you press on it you are redirected to a sqlite editor where the exact code is passed as in the tutorial but if you run it it fails:




maybe they forgot to update the tutorial?!
 
Upvote 0

teddybear

Well-Known Member
Licensed User
B4X:
UPDATE tblClientGivenMedicine_Temp
SET Notes = '555'
where JobDate='12/20/2025' and DrugID=11197
ORDER by Created DESC
LIMIT 1;
The sql has no problem if ORDER BY and LIMIT clauses for UPDATE are available.
It will update the 1st record which selected by conditions and orderby key.

B4X:
select * from emp where nm="Alice" order by idx desc;

B4X:
update emp set boss=168
where nm="Alice"
ORDER by idx desc
LIMIT 1;
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
It is just a BAD idea to try and use an ORDER BY and LIMIT in an update query. If you are going to modify data you better know EXACTLY what you are modifying.
But if you must some DB engine specific version of LucaMs's post 13 will get you there with only one trip to the server.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…