FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[MySQL] Most used values in a column





Stubru Freak
I have a table this way:

Code:

+=========+
+ name
+=========+
| john
+---------+
| joe
+---------+
| john
+---------+
| john
+---------+
| joe
+---------+
| john
+---------+


And so on, (of course with more then two names)

I need to get a list of the 500 names that are most used in that column. I have no idea how to do this, please help.
Rhysige
Whats your question? How to identify different names? how to enter it?
kv
select Name, count(Name) as cnt from name_tbl
group by Name f
order by cnt desc
limit 500;

This sql returns name and number of repetitions of 500 most repeated names in the table.
Stubru Freak
Thank you very much, it does indeed!
Rhysige
kv I can tell I would hate reading your scripts Razz I get so annoyed if people put select collum rather than SELECT `collum`
kv
Rhysige wrote:
kv I can tell I would hate reading your scripts Razz I get so annoyed if people put select collum rather than SELECT `collum`


Smile Well, what a reason to hate me. SQL standard doesn't enforce using any quotes around column name. It is mysql documents which contain these quotes. Refer to any other database (like oracle or db2 or sybase) docs. You will never find these back-ticks.

Even in mysql, these sqls work without the back-quotes.
Related topics
[beginner] CSS Font property :
Mysql error!
How to center something horizontally AND vertically...
The Basics (php, mysql etc)
help please...
Support Danish
AJAX tutorial [2nd part now updated]
Reading MySQL values in reverse
Webdesign Magazine
Where can I get a free wiki that looks JUST like wikipedia?
vBulletin installation: Files upload, Database setup
PHP on server without database
Questions for Christians
Is Oracle better thab MySQL ??
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.