ashburnham Posted November 26, 2007 Share Posted November 26, 2007 Probably a simple one but I'm a bit of a novice so any help would be appreciated. Within my database I have a table called customer and a column within called refer. The refer column is populated by a single name such as Steve, Bob, Joe, Dave, Bob, Derek, Joe, Bob, etc... I want to run a query to get all occurrences of a name and the number of times it occurs and display it all in a nice little table but can't think how to do this ??? Desired outcome (using the above example) should be something like: Name |Occurrence Bob| 3 Joe| 2 Dave| 1 Derek| 1 Steve| 1 Any help would be appreciated - thanks... P.S. Being able to sort into name or occurrences order would be preferred but not vital. Link to comment https://forums.phpfreaks.com/topic/78948-solved-mysql-query-help/ Share on other sites More sharing options...
fenway Posted November 26, 2007 Share Posted November 26, 2007 Try this: SELECT nameField, COUNT( nameField ) AS occurence FROM yourTable GROUP BY nameField ORDER BY occurence DESC Link to comment https://forums.phpfreaks.com/topic/78948-solved-mysql-query-help/#findComment-399522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.