Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Query with limit cause SQLite

Tags:

sqlite

i have table in SQLite named TBL_data

i have two fields id and name

All id is set to the -1

i want to update first occurrence of record

for this i have used

update TBL_data set name = 'XYZ' where id = -1 limit 1

it shows error, is there any other way ?

like image 597
Prashant Tukadiya Avatar asked Mar 16 '15 06:03

Prashant Tukadiya


1 Answers

That query works only if you have compiled SQLite with SQLITE_ENABLE_UPDATE_DELETE_LIMIT.

If this is not the case, you have to use some unique key of your table to determine the rows:

UPDATE tbl_data
SET ...
WHERE rowid IN (SELECT rowid
                FROM tbl_data
                WHERE ...
                ORDER BY ...
                LIMIT 1)
like image 177
CL. Avatar answered Sep 28 '22 13:09

CL.