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


Creating a MYSQL "most common" query





3shades
hey guys,

Is there a way I can create a query to show me the most common value in a table?

im using dreamweaver if thats any help,

thanks,

ben,
leodv
Maybe you could try

Code:
SELECT "column_name",
COUNT("column_name") AS NumOccurrences
FROM "table_name"
GROUP BY "column_name"
HAVING ( COUNT("column_name") > 1 )


It will list out counts of a column repeated two or more times. You could then sort by the biggest amount of NumOccurrences first, and retrieve the first cell value of the "column_name". Hope this helps, or rather that you understand what I'm trying to explain.
kv
Code:

SELECT "column_name",
COUNT("column_name") AS NumOccurrences
FROM "table_name"
GROUP BY "column_name"
HAVING ( COUNT("column_name") = MAX(COUNT("column_name") )


should return you single row with column name repeated max times.
Related topics
SQL Basics
[Question] Visual Basic C++, PHP, mySQL language guides...
The Basics (php, mysql etc)
Reducing Exploits
Best way to prevent SQL injection attacks
PHP-Fusion
A very good PHP MySQL Tutorial
How to update multiple rows in mysql with one query?
Online Database programme
What is the most common type of Internet Connection?
PHP-Fusion | An Open Source CMS | PHP & MySQL Based
Everything object oriented - WHY?!
List of all the common denominators across all religions
Most common reason of breakup
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.