The best way is:

SELECT person_name, count(*)
FROM table_name
GROUP BY person_name
ORDER BY 2 DESC


----- Original Message ----- 
From: "Daniel Clark" <[EMAIL PROTECTED]>
To: "Brian Dunning" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, June 03, 2004 10:30 AM
Subject: Re: [PHP] Best way to sort?


> SELECT DISTINCT person_name, count(*)
> FROM table_name
> GROUP BY person_name
> ORDER BY 2 DESC
> 
> > I'm not sure if this is a complex SQL query or a PHP array sorting
> > thing, but what's the best way to take this data:
> >
> >    Tom
> >    Greg
> >    Brian
> >    Tom
> >    Brian
> >    Tom
> >
> > And return the following results, sorted by number of records:
> >
> >    Tom - 3
> >    Brian - 2
> >    Greg - 1
> >
> > Any thoughts?
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to