in reply to Re: (OT) MySQL query to limit and sort
in thread (OT) MySQL query to limit and sort

Using that I don't get any rows back.

my $data = qq[SELECT id, url, images, Total FROM temp WHERE id > (SEL +ECT MAX(id) - 10) ORDER BY Total DESC];

Replies are listed 'Best First'.
Re^3: (OT) MySQL query to limit and sort
by saberworks (Curate) on Feb 03, 2006 at 22:47 UTC
    Apologies:
    SELECT id, total FROM some_table WHERE id > (SELECT MAX(id) FROM some_table) - 10 ORDER BY total DESC
      It's slightly fragile in the face of deletions. Say you have records 140 through 160, delete 150 through 159, then run this query. That will only return record 160, while I would expect (141 .. 149, 160). But that may just be my interpretation of the OP's question asking for a top 10.