FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a 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.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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