0

I have a table like below

table name student

id student status date
1 Mr.1 0 11-2-2022
2 Mr.1 1 10-2-2022
3 Mr.2 0 10-2-2022

now i want to make update query in only 40 rows where student is equal to Mr.1 & status is equal to 0 and date is equal to current month then update status of 40 rows to 1. now if i run the query again it will count the 40 rows again and check is there any rows contain 0 or not , if 39 rows contains 1 and only 1 rows contains 0 then it will update to only one rows.

this is my basic query

UPDATE student SET status= '1' WHERE student = 'Mr.1' ORDER BY id DESC LIMIT 40;
  • Do you have any auto_increment key field (e.g. id / serial) in your student table? – Ken Lee Nov 02 '22 at 16:10
  • 1
    https://stackoverflow.com/questions/6289729/mysql-update-query-with-limit – vee Nov 02 '22 at 16:12
  • 1
    You need to add `status = '0'` and the date constraint to your `WHERE` clause as well. Now it will just update the same records every time. – M. Eriksson Nov 02 '22 at 16:28

0 Answers0