How can I make this work - gives me #1093 - You can't specify target table 'Orders' for update in FROM clause
Update Orders set flag = 0 where orders_id = (select orders_id from orders ORDER BY orders_id DESC LIMIT 1)
How can I make this work - gives me #1093 - You can't specify target table 'Orders' for update in FROM clause
Update Orders set flag = 0 where orders_id = (select orders_id from orders ORDER BY orders_id DESC LIMIT 1)
You need to wrap it in a subquery (creating a temporary table)
Update Orders
set flag = 0
where orders_id =
(
SELECT x.orders_id
FROM
(
select orders_id
from orders
ORDER BY orders_id DESC
LIMIT 1
) x
)
or
Update Orders
set flag = 0
where orders_id =
(
SELECT x.orders_id
FROM
(
select MAX(orders_id) orders_id
from orders
) x
)
it looks like you are trying up update the last order in the table? try
Update Orders set flag = 0 ORDER BY orders_id DESC LIMIT 1;
Mysql doesn't support updating a table while using it in a subquery..