How can I get record 34 of a table if the last record is record 35 ?
Here is the query to get the second last row of a table in MySQL. mysql> select *from secondLastDemo order by StudentId DESC LIMIT 1,1; The output displays the second last record.
You can use UNION to get the previous and next record in MySQL. Insert some records in the table using insert command. Display all records from the table using select statement.
Use the aggregate MAX(signin) grouped by id. This will list the most recent signin for each id . To get the whole single record, perform an INNER JOIN against a subquery which returns only the MAX(signin) per id. Save this answer.
If you are AUTO_INCREMENT with column, then you can use last_insert_id() method. This method gets the ID of the last inserted record in MySQL.
Simplest method
SELECT * FROM tab ORDER BY col DESC LIMIT 1,1
This will pick one record starting with the 2nd LIMIT 1,1 means skip first and pick next
The order by will have to be done so that last is first The col mentioned will most probably be id
If you know the number of the record you want however why can't you just select where id=34?
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