LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-17-2003, 09:17 AM   #1
niehls
Member
 
Registered: Jun 2002
Location: Sweden
Distribution: slack, redhat
Posts: 91

Rep: Reputation: 15
getting the most frequent value from mysql table


as the header says; i'm trying to get the most frequent value out of a table using php.
say i have a table used for logging user-activity on my homepage.
the table log has a column "action" which contains information on the current activity of the user.

i want to retrieve information on which action is the most frequent, second frequent and so forth.

anybody here know how to achieve this?
//
niehls
 
Old 02-17-2003, 09:58 AM   #2
Stuka
LQ Newbie
 
Registered: Feb 2003
Location: Houston, TX
Distribution: Debian/RedHat/Slack
Posts: 12

Rep: Reputation: 0
You'll need to use the COUNT grouping function - the MySQL docs have a pretty good explanation of how to do it.
 
Old 02-17-2003, 10:00 AM   #3
madhippy
LQ Newbie
 
Registered: Dec 2002
Posts: 8

Rep: Reputation: 0
something along the lines of

SELECT action, COUNT(action) AS ActionCount
FROM log
GROUP BY action
ORDER BY COUNT(action) DESC;

??
 
Old 02-17-2003, 10:48 AM   #4
niehls
Member
 
Registered: Jun 2002
Location: Sweden
Distribution: slack, redhat
Posts: 91

Original Poster
Rep: Reputation: 15
thx..i used a php script instead...but now i know for future needs..
 
Old 01-29-2005, 06:49 AM   #5
dearsina
LQ Newbie
 
Registered: Jan 2005
Distribution: Actually, I use WinXP...
Posts: 1

Rep: Reputation: 0
Just a quick note for people who might be searching for "most frequent value out of a table " and have found madhippys SQL statement, it's great and works, with one little exception, it should read:

Code:
SELECT action, COUNT(action) AS ActionCount
FROM log
GROUP BY action
ORDER BY ActionCount DESC; //<- ActionCount instead of COUNT(action)
sina
london

Last edited by dearsina; 01-29-2005 at 06:51 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL db table tommytomato Linux - General 10 08-24-2004 05:57 AM
MySQL: Can't use '(' or ')' in table name Mikessu Linux - Software 0 08-03-2004 03:59 AM
MySQL non-realtime table-by-table mirroring Passive Linux - Software 1 01-20-2004 12:11 PM
How to import MS ACCESS Table including OLE filed into the MySQL Table ? myunicom Linux - General 1 11-28-2003 11:30 AM
deleted mysql table in mysql now cant do anything nakkaya Linux - Software 0 03-18-2003 06:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration