[nycphp-talk] Can I do this in one query?
tom at supertom.com
Sat Apr 9 00:28:39 EDT 2005
Can I do this in one query?
Suppose I have a three column table (it is really not, but I'm trying to
keep it simple)
I would like to select the top 5 in each category with the most amount of
points, and group them by category, to ultimately be displayed like this:
I see that I can do this in two queries and some PHP code, by driving a loop
with the DISTINCT category, and saying something like
SELECT name,points FROM scores WHERE category='$category' ORDER BY points
DESC LIMIT 0,5
but there must be a better way
More information about the talk