7 messages in com.mysql.lists.mysqlRe: LIMIT Question
FromSent OnAttachments
Dirk Bremer28 Jun 2006 13:15 
Dan Buettner28 Jun 2006 13:27 
Dirk Bremer28 Jun 2006 13:39 
Chris White28 Jun 2006 13:46 
Dan Buettner28 Jun 2006 13:53 
Dirk Bremer28 Jun 2006 14:18 
William R. Mussatto29 Jun 2006 09:30 
Subject:Re: LIMIT Question
From:Dan Buettner (drbu@gmail.com)
Date:06/28/2006 01:27:20 PM
List:com.mysql.lists.mysql

Depends what you mean by "last" - you could show the 50 with the latest datestamps by ending your query with something like:

ORDER BY datestampcolumn DESC LIMIT 50;

or the 50 with the highest ID numbers, same thing:

ORDER BY id DESC LIMIT 50;

only real problem there is then they're sorted highest to lowest, but it is still the "last" 50.

Dan

On 6/28/06, Dirk Bremer <Dirk@nisc.coop> wrote:

Is there a way to use a LIMIT clause to show the last X amount of rows or a way to emulate this behavior? For example, a table has somewhere between 1000 and 2000 rows, but you just want to see the last 50. These last 50 might be the most recent entries, for example. Can this be done in single query?