Hey there,
I need help with writing a query so I figured I'd ask here. Let me thank you in advance for your answer.

I need to see how often a value inside a certain column appears in a table. Say for example I have a table Person, that has a field name.

I want to know top five most frequently occuring names, along with the number indicating how often each appears.

Thank you.

Recommended Answers

Use COUNT, GROUP BY, and ORDER BY

Jump to Post

All 4 Replies

Use COUNT, GROUP BY, and ORDER BY

thanks for the help pritaeas,

this is what I am trying:

select name, count(name) frequency from (select name from person) order by frequency

and I am expeting:

someName|12
anOtName|7

but it is not working at all. hmm. can you please give some more hints?

SELECT `name`, COUNT(`name`) AS `frequency` 
FROM `person` 
GROUP BY `name` 
ORDER BY `frequency` DESC

This is tested on MySQL 5.5

Hey pritaeas,
thank you very much for your help. sorry for late reply. That was helpful enought to get me through the block. thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.