Just wondering if there is a simple query that I could use to get the second last record when selecting max id.
SELECT MAX(`EventID`) FROM `event`;
Thank you
You can use: EDIT: (added Bill's suggestion which is better)
SELECT (`EventID`) FROM 'event' ORDER BY 'EventID' DESC LIMIT 1 OFFSET 1
OR:
SELECT `EventID` FROM (SELECT (`EventID`) FROM 'event' ORDER BY 'EventID' DESC LIMIT 2) ORDER BY 'EventID' ASC LIMIT 1
This solution is more general and will also work if your EventID column has gaps
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