Hi!

There are plenty of funky ways to do this. :-)

The easiest and fastest way would simply need an AUTO_INCREMENT column
on your table. Then, you might be able to do something like this (with
MIGHT being the operative word):

SELECT * FROM table ORDER BY auto_inc_column DESC LIMIT 22;

I've just tested this on a very large table and it gives the required
results, but probably in the reverse order to what you want. You could
easily reverse the order of rows in whichever language you're accessing
the DB with.

Hope this helps!

Regards,

Chris



On Sun, 2003-12-14 at 13:06, Moritz von Schweinitz wrote:
> AFAIK databases like mysql usually dont (and cant) guarantee that they 
> will maintain the order of rows the same way they were inserted - it's 
> that whole 'relational' thing, methinks.
> the official way would be to simply add a timestamp field (which gets 
> filled automagically every time you insert something into that table), 
> and order by that. hacking up a little perl-script that simply iterates 
> over all rows, and inserts a "row number" would be trivial, and should 
> usually work, but mysql is not obligated to maintain that order (i think)
> 
> cheers,
> 
> M.
> 
> Matthew Richardson wrote:
> 
> > Hello all,
> > 
> > Still a newbie with MySQL, I am running version 4.01 and a Linux box. We 
> > are writing information
> > into the tables at a regular rate approx 20 time per hour. with 22 rows 
> > of information.
> > 
> > What I am trying to work out is how to read the last 22 rows of 
> > information that has been written to
> > the Database.
> > 
> > Select (count(*)-22) from Database
> > will return me the record number 22 numbers from the very last record. 
> > This is great but
> > when I try and incoperate the (count(*)-22) into a query I get responce 
> > about grouping.
> > 
> > Just wondering if any one else has had a need to return the last few 
> > rows in a table that might be able to shed some light on the subject !
> > 
> > regards Matthew Richardson
> > 
> > 
> 


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

Reply via email to