Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: (OT) MySQL query to limit and sort

by saberworks (Curate)
on Feb 03, 2006 at 22:12 UTC ( [id://527829]=note: print w/replies, xml ) Need Help??


in reply to (OT) MySQL query to limit and sort

UPDATE: Sorry I put a broken query... here is the fixed one:
SELECT id, total FROM some_table WHERE id > (SELECT MAX(id) FROM some_table) - 10 ORDER BY total DESC
(old one here for historical purposes):
SELECT id, total FROM some_table WHERE id > (SELECT MAX(id) - 10) ORDER BY total DESC

Replies are listed 'Best First'.
Re^2: (OT) MySQL query to limit and sort
by Anonymous Monk on Feb 03, 2006 at 22:40 UTC
    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];
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://527829]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found