[thelist] Doh! question for MySQL

rudy r937 at interlog.com
Wed Feb 14 00:28:02 CST 2001


> I need a way to select the last 10 inserts into a db table.

hi walker

> the table has a primary key (orderitemid) that is auto-numbered..

well, that does help

    select foo, bar, baz, bat
      from yourtable
     order by orderitemid desc
      limit 10


here's the relevant portion of the mysql documentation --

     The LIMIT clause can be used to constrain the number
     of rows returned by the SELECT statement. LIMIT takes
     one or two numeric arguments. If two arguments are given,
     the first specifies the offset of the first row to return, the
     second specifies the maximum number of rows to return.
     The offset of the initial row is 0 (not 1):

        mysql> select * from table LIMIT 5,10;  # Retrieve rows 6-15

     If one argument is given, it indicates the maximum number
     of rows to return:

       mysql> select * from table LIMIT 5;     # Retrieve first 5 rows

     In other words, LIMIT n is equivalent to LIMIT 0,n.


http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#SE
LECT


rudy.ca






More information about the thelist mailing list