Thursday, July 31, 2008

last n records in a query

I'm using mysql for this:

This is straightforward:

SELECT * FROM tab LIMIT 0, 10

will display the first 10 rows from the table tab.

SELECT * FROM tab LIMIT 5, 2

display rows 6 and 7 (5 is the offset, 2 the count)

And:

select * from (select * from TAB order by id desc limit 5 ) TA order by id;

display the LAST 5 rows.

No comments: