开发者

Multiple update in mysql using a subquery

Please, I want a query that will help me to update the first 200 rows of the bill column to 3 after selecting the first 200 rows from the dlr table. I also want there to be no repetition when my select statement is coming back to p开发者_如何学Goick another 200 rows.

It will only pick the bill column rows that are not 3.

Below is the query i wrote and it is giving me below mentioned error.

'LIMIT & IN/ALL/ANY/SOME subquery:
UPDATE dlr SET bill = 3 
WHERE dlrid IN (SELECT dlrid FROM dlr WHERE bill = 0 LIMIT 0,200);

Error I am Receiving = This version of MySQL doesn't yet support

Can anybody help me out?


You don't need the subquery.

UPDATE dlr SET bill = 3 WHERE bill = 0 LIMIT 200;


Move the limit clause out from the subquery into the update query:

UPDATE dlr SET bill = 3 WHERE dlrid IN (SELECT dlrid FROM dlr WHERE bill = 0) LIMIT 200;

There is no need to use a range, since the next 200 is guaranteed to be distinct from the first 200, since bill changes from 0 to 3.

For this to work, dlrid must be unique in dlr, which by the name, I'm guessing it is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜