Dan,

That might be close. The rows are inserted with an auto-increment
primary key, but I have no ready way of knowing what the latest 50-IDs
are. There are also various date columns, but I won't readily know the
dates in this scenario.

The goal of the query, which currently returns all of the results, is to
find all entries for a given customer regardless of when they occurred.
I would like no more than the last 50 rows inserted for this customer
(this could be based upon the auto-increment value) and would prefer to
have them ordered within the 50-possible results in the order they were
inserted, from lowest-ID to the highest-ID. This will prevent the query
from showing possible hundreds of results. 

There are multiple customers in the table.

Dirk Bremer - Senior Systems Engineer - ESS/AMS - NISC Lake St. Louis MO
- USA Central Time Zone
636-755-2652 fax 636-755-2503

[EMAIL PROTECTED]
www.nisc.coop 

> -----Original Message-----
> From: Dan Buettner [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, June 28, 2006 15:28
> To: Dirk Bremer
> Cc: mysql@lists.mysql.com
> Subject: Re: LIMIT Question
> 
> 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 <[EMAIL PROTECTED]> 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?
> >
> > Dirk Bremer - Senior Systems Engineer - ESS/AMS - NISC Lake 
> St. Louis MO
> > - USA Central Time Zone
> > 636-755-2652 fax 636-755-2503
> >
> > [EMAIL PROTECTED]
> > www.nisc.coop
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:    
> http://lists.mysql.com/[EMAIL PROTECTED]
> >
> >
> 

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to