Re: Most Occurring
| From: | php3 at developersdesk dot com | Date: | Thu, 22 Feb 2001 23:33:52 +0000 |
| Subject: | Re: Most Occurring | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-6893@lists.php.net to get a copy of this message | ||
Addressed to: Dale Frohman <dfrohman@durocom.com>
php-db@lists.php.net
** Reply to note from Dale Frohman <dfrohman@durocom.com> Thu, 22 Feb 2001 10:34:47 -0500
(EST)
>
> Is there anyway with a mysql query to find which item in a particular
> field in a table occurs the most frequently?
>
> ie:
>
> table things
>
> field morethings
>
> item1
> item2
> item1
> item1
>
> I would like a query that runs and pulls whatever occurs the most. In
> this case "item1"
Contrary to popular opinion, MySQL is quite powerful, and can do quite a
bit more than some seen to think around here. Grumble, grumble. You
can learn a lot from few hours reading the F* manual.
Try this:
SELECT COUNT(*) AS Count, morethings
FROM things
GROUP BY morethings
ORDER BY Count DESC
LIMIT 1
Result
+-------+------------+
| Count | morethings |
+-------+------------+
| 3 | item1 |
+-------+------------+
Rick Widmer
Internet Marketing Specialists
http://www.developersdesk.com