Hassan Hassan - 4 months ago 12
MySQL Question

how to get second last row from mysql database

Hi guys I just made a query to get second last row from database

Here Is code:


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


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

in older version this code work fine.

what is problem that i have 10 results in table and when i submit this query its give me 9 row but when 9 row delete from table now i have 8 and 10 but this code give me 10 not previous please help thanks in advance

Answer
SELECT * FROM Categories ORDER BY CategoryID  DESC LIMIT 1,1