Nawin Nawin - 5 months ago 11
MySQL Question

update only 50 records per date mysql

Hi i have a table for coupons in there i got lots of data's inserted already. if one user subscribe that table will be update and assign to that coupon to user.

ID coupon user created Instance
1 xxxx abc@gmail.com 2016-06-15 1
2 xxxx def@gmail.com 2016-06-15 1
3 xxxx ghi@gmail.com 2016-06-15 1
4 xxxx ijk@gmail.com 2016-06-15 1
5 xxxx 0000-00-00 0
6 xxxx 0000-00-00 0
7 xxxx 0000-00-00 0


if the user subscribe user mail and date will be create and instance is changed to 1. I want to update only 50 users per day how can i check with query this condition? Help me.

Answer

You can use a query like this. after execution you can test with mysqli_affected_rows how many rows are changed.

UPDATE yourTable
  SET `Instace` = 1
  , `USER` = 'theEmail'
  , `created` = now()
WHERE
  id = (SELECT id FROM yourTable WHERE Instance = 0 AND `USER` IS NULL LIMIT 1)
AND
 50 > (SELECT COUN(*) FROM yourTable WHERE `created` = NOW());
Comments