I would like to detele the row with the biggest order_id, I tried this:
DELETE FROM orders WHERE MAX(order_id)
But this is wrong! any other ideas?
Thank you for your time.
First idea (among many others that had exactly the same):
DELETE FROM orders
WHERE order_id =
( SELECT MAX(order_id)
FROM orders
)
Unfortunately MySQL complains with:
> ERROR 1093 (HY000): You can't specify target table 'orders' for update in FROM
> clause
Two ways to bypass the error:
DELETE FROM orders
WHERE order_id =
( SELECT maxo
FROM
( SELECT MAX(order_id) AS maxo
FROM orders
) AS tmp
)
or:
DELETE FROM orders
ORDER BY order_id DESC
LIMIT 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With