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;