Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MaxDB - Everything about MaxDB, formerly known as SAP DB
MySQL++ - Programming with the C++ API to MySQL
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
ODBC - ODBC with the MySQL Connector/ODBC driver
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
mysql openssl Question
mysql:it 's a db not a dbms how it 's possible?!
Does the binary log enabling affect the MySQL performances?
Strange behavior, Table Level Permission
FULLTEXT query format question
Preventing Duplicate Entries
Comparing and writing out BLOBS
Executing MySQL Commands From Within C Program
Can 't access mysql after kernel upgrade
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Downgrade Mysql from 4 to 3 23
MySQL Cluster Software
mysql test 4 1 fails with the gis test
ERROR 2002: Can 't connect to local MySQL server through socket
Getting Identity after INSERT
Update one field with more fields from another table
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
mysql have same function mthod as Oracle decode()
 
LIMIT Question

LIMIT Question

2006-06-29       - By William R. Mussatto

 Back
Reply:     1     2     3     4     5     6     7  

Have your where clause select the customer, sort result by autoincrement
column DESC limit 50

Only problem is the order would be the inverse (i.e., last in first
displayed) from your goal.  Only way I can thing to go around this would
be to select into a temp table and then sort that into the desired
sequence.
Just a thougth.

Dirk Bremer said:
> 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
>
> dirk.bremer@(protected)
> www.nisc.coop
>
>> -- --Original Message-- --
>> From: Dan Buettner [mailto:drbuettner@(protected)]
>> Sent: Wednesday, June 28, 2006 15:28
>> To: Dirk Bremer
>> Cc: mysql@(protected)
>> 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 <Dirk.Bremer@(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
>> >
>> > dirk.bremer@(protected)
>> > www.nisc.coop
>> >
>> > --


-- ----

William R. Mussatto, Senior Systems Engineer
http://www.csz.com
Ph. 909-920-9154 ext. 27
FAX. 909-608-7061


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=mysql@(protected)