Page 1 of 1

select LIMIT last?

Posted: Mon Mar 01, 2004 6:31 pm
by Unipus
How can I structure a LIMIT statement to return only the last result?

Posted: Mon Mar 01, 2004 9:27 pm
by goldfish
http://www.mysql.com/doc/en/SELECT.html

have a look at LIMIT with 2 arguments
eg:
mysql> SELECT * FROM table LIMIT 5,10; # Retrieve rows 6-15

so:
mysql> SELECT * FROM table LIMIT 5,1; will return row 6

(The offset of the initial row is 0 not 1)

Posted: Mon Mar 01, 2004 9:28 pm
by goldfish
ps - it is great for pagination of recordsets

Posted: Tue Mar 02, 2004 3:16 am
by Wayne
or you could reverse the order of the results by adding a ORDER BY fieldname DESC then putting you LIMIT 1 on the end