Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MariaDB, UPDATE with SELECT, LIMIT in subquery

I am trying to update a field in a table using a SELECT query, when I execute I see the errors:

08:10:16    UPDATE TABLE `Tesla-20240105` SET `state`=1 WHERE `id` IN (SELECT `id` FROM `Tesla-20240105` WHERE `state` IS NULL LIMIT 10)    Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'TABLE `Tesla-20240105` SET `state`=1 WHERE `id` IN (SELECT `id` FROM `Tesla-2...' at line 1  0.00013 sec
08:10:48    UPDATE `Tesla-20240105` SET `state`=1 WHERE `id` IN (SELECT `id` FROM `Tesla-20240105` WHERE `state` IS NULL LIMIT 10)  Error Code: 1235. This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'    0.040 sec

The table can have potentially 300,000 records, the above is an attempt to select just 10 where the state is NULL and modify them, any suggestions on how I can achieve this ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

How about moving limit out of subquery, into the main query?

UPDATE `Tesla-20240105` SET 
  `state`=1 
WHERE `id` IN (SELECT `id` 
               FROM `Tesla-20240105` 
               WHERE `state` IS NULL
              ) 
LIMIT 10
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading