3 ms·
It even has its own tag on StackOverflow: https://stackoverflow.com/questions/tagged/greatest-n-per-group https://stackoverflow.com/questions/tagged/greatest-n-
by jodrellblank 4y ago
It even has its own tag on StackOverflow: https://stackoverflow.com/questions/tagged/greatest-n-per-group https://stackoverflow.com/questions/tagged/greatest-n-per-gr...
People who want it, want it with an order.
Look at
https://stackoverflow.com/questions/121387/fetch-the-row-which-has-the-max-value-for-a-column/123481 https://stackoverflow.com/questions/121387/fetch-the-row-whi...
and
https://stackoverflow.com/questions/3800551/select-first-row-in-each-group-by-group https://stackoverflow.com/questions/3800551/select-first-row...
and
https://stackoverflow.com/questions/8748986/get-records-with-highest-smallest-whatever-per-group/8749095 https://stackoverflow.com/questions/8748986/get-records-with...
and their combined thousands of votes and dozens of answers, all full of awkward workaround or ill-performing or specialised-for-one-database-engine code for this common and desirable thing which would be trivial with a couple of boring loops in Python.