I have a table named status_t:
**id** **page** **status** **locked**_by
1 0 2 0
1 1 2 0
1 2 2 0
2 0 0 0
2 1 2 0
2 2 2 0
primary key is ( id, page) .
In the above example I would like to update all the rows that all pages have status = 2.
i.e. the query should update all the rows with id = 1 to status 3. So the table will become
**id** **page** **status** **locked**_by
1 0 3 1
1 1 3 1
1 2 3 1
2 0 0 0
2 1 2 0
2 2 2 0
I have tried:
SELECT * FROM status_t AS t
WHERE id IN
(SELECT id FROM status WHERE status = 0) LIMIT 10
the above query fetches the rows to be updated but I cannot do that:
UPDATE status_t as S1 WHERE id IN
(SELECT id FROM status_t WHERE status = 2)
SET S1.status = 3, S1.locked_by = 1
EDIT:
THE ABOVE TABLE IS JUST AN EXAMPLE.
I do not want to update WHERE id = 1 . I just want to update rows no matter the id that have status = 2 for the same id. In the above example if the row with key (2, 2) had status = 2 then it should be updated.