select LIMIT last?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

select LIMIT last?

Post by Unipus »

How can I structure a LIMIT statement to return only the last result?
User avatar
goldfish
Forum Newbie
Posts: 2
Joined: Mon Mar 01, 2004 9:27 pm
Location: melbourne .au

Post 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)
User avatar
goldfish
Forum Newbie
Posts: 2
Joined: Mon Mar 01, 2004 9:27 pm
Location: melbourne .au

Post by goldfish »

ps - it is great for pagination of recordsets
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post 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
Post Reply