Addressed to: Dale Frohman <[EMAIL PROTECTED]>
[EMAIL PROTECTED]
** Reply to note from Dale Frohman <[EMAIL PROTECTED]> 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
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]