#SUPPLEMENTARY INFORMATION
Specifying UPDATEs using subqueries can be dangerous business.
Back on Feb 21, 2011 someone asked this question : Problem with MySQL subqueryProblem with MySQL subquery.
I did a little research and discovered something disturbing: During the optimization of a query that involves a subquery against itself, it is entirely possible for rows to intermittently disappearDuring the optimization of a query that involves a subquery against itself, it is entirely possible for rows to intermittently disappear.
Therefore, please consider the error message
Error code: 1093
You can't specify target table 'Tab1' for update in FROM clause.
a friendly warning shot from MySQL not to write queries with that style
UPDATE Tab1
SET Tab1.a = '3'
WHERE
Tab1.id IN (
SELECT Tab1.id
FROM Tab1, Tab2
WHERE Tab1.b = Tab2.b AND Tab1.c = '4'
);
@dezso's answer@dezso's answer (gets a +1), which employs the use of an UPDATE JOIN
, is more palatable to the MySQL Query Optimizer