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
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
SELECT MAX(EventID)
FROM event
WHERE EventID<(SELECT MAX(EventID) FROM event)
select max(billno) from bill_information
solution
select max(billno) from bill_information where billno <(select max(billno) from bill_information)
This will help if you making billing software.That the billno (primary key with indexed) deleted and you want the billno between the billno
--213763 billno
select max(billno) from bill_information where billno <213763
i did something similar to this
$query_anakuklwsh = "SELECT * FROM anakuklwsh WHERE id=".$row_anakuklwsh['id']." -1";
I actually managed to figure it out
SELECT MAX(`EventID`) FROM `event` WHERE `EventID` = (SELECT MAX(`EventID`) -1 FROM `event`);