Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: MAX and GROUP BY in DBIx::Class

by tonyc (Hermit)
on Nov 15, 2025 at 04:32 UTC ( [id://11166732]=note: print w/replies, xml ) Need Help??


in reply to MAX and GROUP BY in DBIx::Class

You can get what you originally asked for with SQL, though since more than one row with the same name can have the same score, you might get more than one row with the same name/score and a different id. Using your data:
sqlite> select * from scores; 1|John|24 2|John|60 3|Mary|4 4|John|10 5|Kate|30 6|Mary|20 sqlite> select a.id, a.name, a.score from scores a join ( select name, max(score) as "score" from scores group by name ) +b on a.name = b.name and a.score = b.score; 2|John|60 5|Kate|30 6|Mary|20 sqlite> insert into scores values(7, 'John', 60); sqlite> select a.id, a.name, a.score from scores a join ( select name, max(score) as "score" from scores group by name ) +b on a.name = b.name and a.score = b.score; 2|John|60 5|Kate|30 6|Mary|20 7|John|60

I couldn't figure out has to express that in DBIx::Class.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2025-12-09 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (88 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.