Första idén (bland många andra som hade exakt samma sak):
DELETE FROM orders
WHERE order_id =
( SELECT MAX(order_id)
FROM orders
)
Tyvärr klagar MySQL med:
> ERROR 1093 (HY000): You can't specify target table 'orders' for update in FROM
> clause
Två sätt att kringgå felet:
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