最初のアイデア(まったく同じものを持っていた他の多くの中で):
DELETE FROM orders
WHERE order_id =
( SELECT MAX(order_id)
FROM orders
)
残念ながら、MySQLは次のように文句を言います:
> ERROR 1093 (HY000): You can't specify target table 'orders' for update in FROM
> clause
エラーを回避する2つの方法:
DELETE FROM orders
WHERE order_id =
( SELECT maxo
FROM
( SELECT MAX(order_id) AS maxo
FROM orders
) AS tmp
)
または:
DELETE FROM orders
ORDER BY order_id DESC
LIMIT 1