我怎样才能完成这项工作 - 给我 #1093 - 您不能在 FROM 子句中指定目标表“订单”进行更新
Update Orders set flag = 0 where orders_id = (select orders_id from orders ORDER BY orders_id DESC LIMIT 1)
我怎样才能完成这项工作 - 给我 #1093 - 您不能在 FROM 子句中指定目标表“订单”进行更新
Update Orders set flag = 0 where orders_id = (select orders_id from orders ORDER BY orders_id DESC LIMIT 1)
您需要将其包装在子查询中(创建临时表)
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
)
或者
Update Orders
set flag = 0
where orders_id =
(
SELECT x.orders_id
FROM
(
select MAX(orders_id) orders_id
from orders
) x
)
看起来您正在尝试更新表中的最后一个订单?尝试
Update Orders set flag = 0 ORDER BY orders_id DESC LIMIT 1;
Mysql 不支持在子查询中使用表时更新表。