Første idé (blandt mange andre, der havde præcis det samme):
DELETE FROM orders
WHERE order_id =
( SELECT MAX(order_id)
FROM orders
)
Desværre klager MySQL over:
> ERROR 1093 (HY000): You can't specify target table 'orders' for update in FROM
> clause
To måder at omgå fejlen på:
DELETE FROM orders
WHERE order_id =
( SELECT maxo
FROM
( SELECT MAX(order_id) AS maxo
FROM orders
) AS tmp
)
eller:
DELETE FROM orders
ORDER BY order_id DESC
LIMIT 1