0

我怎样才能完成这项工作 - 给我 #1093 - 您不能在 FROM 子句中指定目标表“订单”进行更新

Update Orders set flag = 0 where orders_id = (select orders_id from orders ORDER BY orders_id DESC LIMIT 1)
4

2 回答 2

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
    )
于 2012-10-16T14:04:29.350 回答
0

看起来您正在尝试更新表中的最后一个订单?尝试

Update Orders set flag = 0 ORDER BY orders_id DESC LIMIT 1; 

Mysql 不支持在子查询中使用表时更新表。

于 2012-10-16T14:05:28.167 回答