1
I have the following query:
UPDATE cp_feedback_trabalho as a SET
a.visivel = 1
WHERE a.dhEnvio IS NOT NULL AND EXISTS (
SELECT
b.id
FROM cp_feedback_trabalho as b
WHERE
b.id_pessoa_que_enviou = a.id_pessoa_que_recebeu AND
b.id_pessoa_que_recebeu = a.id_pessoa_que_enviou AND
b.id_projeto = a.id_projeto AND
b.dhEnvio IS NOT NULL
)
I get the following error while running:
#1093 - You can’t specify target table 'a' for update in FROM clause
What could be wrong?
What do you want to do? You can also write SQL (in Portuguese and not in SQL, just to understand), like what you want to do, because I don’t understand which relations.
– Fernando Leal
Hello Fernando, I just want to update a field (visible) based on another record that happens to be in the same table that will be updated (cp_feedback_work). The problem is in the variables (a and b)
– user4919
To my knowledge, in Mysql, it is not possible to update a table and use it as a criterion in the clause
WHERE
. A suggestion would be to use a temporary table with the result of aSELECT
of the same table with the clauseWHERE
update (if possible of course).– Wakim