How can I select all BUT the last row in a table?
I know I can select the last via SELECT item FROM table ORDER BY id DESC LIMIT 1
but I want to select ALL but the last.
How can I do this?
Selecting a certain amount and using ASC
won't work because I won't know how many rows there are.
I thought about doing a row count and taking that amount and selecting that -1 and using ORDER BY id ASC
but are there any easier ways?
Thanks.
If Id is unique, you can do it as follows:
SELECT ...
FROM MyTable
WHERE Id < (SELECT MAX(Id) FROM MyTable)
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