Prima idea (tra molte altre che avevano esattamente la stessa):
DELETE FROM orders
WHERE order_id =
( SELECT MAX(order_id)
FROM orders
)
Sfortunatamente MySQL si lamenta con:
> ERROR 1093 (HY000): You can't specify target table 'orders' for update in FROM
> clause
Due modi per aggirare l'errore:
DELETE FROM orders
WHERE order_id =
( SELECT maxo
FROM
( SELECT MAX(order_id) AS maxo
FROM orders
) AS tmp
)
oppure:
DELETE FROM orders
ORDER BY order_id DESC
LIMIT 1