Most commonly occurring string in mysql column.

Posted by MILESMIBALERR on Stack Overflow See other posts from Stack Overflow or by MILESMIBALERR
Published on 2010-05-27T23:52:43Z Indexed on 2010/05/28 0:11 UTC
Read the original article Hit count: 581

Filed under:
|
|

I am making a website where users can vote on which category a page is. They can vote that the page is category, for example: a, b, c, or d. Please don't ask what I am using this for, it is not important, I just want to know how to do it.

I need to find the most commonly occurring category in the mysql row out of all the votes.

Each time a user submits their vote, it submits the "category" that they voted for, and the "page_id".

I have this so far:

select page_id, category

from categories

group by page_id

You cannot simply use a "COUNT(*) where category = 'a'" then repeat it for each category because there is many more categories in the actual project.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql