Why I got an error when try to execute this query:
UPDATE ordersperformers AS t1 SET t1.Status = 1
where not exists (
SELECT 1 FROM ordersperformers
WHERE ordersperformers.Orders_Id = 3
AND (ordersperformers.Status = 1 OR ordersperformers.Status = 2))
AND t1.Orders_Id = 3 AND t1.Users_Id = 5;
Why MySQL does not realize that I work with table ordersperformers
?
Error is:
#1093 - Table 't1' is specified twice, both as a target for 'UPDATE' and as a separate source for data
.
If execute query:
UPDATE ordersperformers SET Status = 1
where ordersperformers.Status NOT IN (1,2)
AND Orders_Id = 3;
It will update anyway one row:
But I dont need update any rows cause table with Orders_Id = 3
has one row with Status = 1