mysql + update top n
UPDATE tableSET status = 1WHERE status = 2ORDER BY idLIMIT 400
Checked in MySQL 5.2.0-falcon-alpha-community-nt-log
, confirmed working.
In your case it's 0
in LIMIT 0, 400
that does not work.
You cannot use the lower bound in UPDATE
's LIMIT
.
Try this:
update tableset status = 1where status = 2LIMIT 400
You can also put an order by clause
update tableset status = 1where status = 2ORDER BY idLIMIT 400
for future reference don't forget to set the safe mode off
SET SQL_SAFE_UPDATES = 0;update YOUR_DATABASE_NAME.TABLE_NAMEset COLUMN_NAM = 0limit 400;SET SQL_SAFE_UPDATES = 1;
MySQL for example does not allow you to update records to prevent you from making mistakes with something called safe mode, so you will have to disable it to be able to update your records.
The other syntax is pretty forward.limit will restrict the number of records returned to a number of your choosing.