Re: count() and grouping

From: Date: Wed, 07 Aug 2002 01:24:15 +0000
Subject: Re: count() and grouping
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-21031@lists.php.net to get a copy of this message
On 07 Aug 2002 08:21:57 -0400 tux <tuxen@gimped.net> wrote: > Hey guys, i have been trying to figure out how to do this but > havent found anything positive, anyway here is the db query that > im doing: > > SELECT submitted_by, COUNT(*) FROM articles GROUP BY submitted_by; > > now what this returns is something like > > submitted_by | count(*) > ======================= > andrew 12 > ben 13 > terry 30 > > however what i want it to do is display by the highest number > first ie terry, ben, andrew, not show them in alphabetical order, > this is so i can display a 'most submissions' type thing. ive > tried using ORDER by count(*) desc and stuff like that but none of > it seems to work?? > > any ideas greatly appreciated > > jo I'm no guy, but try: SELECT submitted_by, COUNT(*) AS cnt FROM articles GROUP BY submitted_by ORDER BY cnt DESC; -- Raquel ============================================================ I never make the mistake of arguing with people for whose opinions I have no respect. --Edward Gibbon

« previous php.db (#21031) next »