I am trying to simple update query with following syntax:
UPDATE cl
SET cl_s="active_"
WHERE id in (
SELECT distinct
c.id
from
cl c,
ac a,
cl_ac ac
where
c.id=ac.cl_id
and
a.id=ac.ac_id
and
c.cl_s="someval"
and
a.ac_no !=""
)
;
The error I get is: Error Code: 1093. You can't specify target table for update in FROM clause
I've read through posts which mention that MySQL is unable to run query like this. I'd want to know a seamless way to restructure such queries to a structure which works. The solution seems to be using joins instead but I can't seem to grasp the concept.
A pseudo code would be helpful, to help with the understanding. Something like
(Main query)
where var in (subquery generating var list)
to
(main query) inner join (subquery generating var list) on var ???