How to get second last row from mysql database

Hi guys, I just made a request to get the second last row from the database

Here is the code:

SELECT TOP 1 * FROM
   (select Top 2 * from Categories ORDER BY CategoryID DESC) x                     
   ORDER BY CategoryID

but this code gives me an error syntax error in the new version.

in the old version, this code works fine.

what's the problem, that I have 10 results in the table, and when I send this query, give me 9 rows, but when 9 rows are removed from the table, now I have 8 and 10, but this code gives me 10 not earlier, please help in advance

+4
source share
3 answers
SELECT * FROM Categories ORDER BY CategoryID  DESC LIMIT 1,1
+15
source
SELECT *  From
(select * from Categories ORDER BY CategoryID DESC LIMIT 2) AS x                    
ORDER BY CategoryID LIMIT 1
+3

, - SELECT * from Categories ORDER BY CategoryID DESC LIMIT 1, 1

+1

All Articles