Cultureshock Posted January 10, 2010 Share Posted January 10, 2010 Basically if I have a table that has data that can be duplicates (say favorite foods as an example) how would I list the top "favorite food" based on how many time a certain food is recorded? Ex; milk milk water beef tomatoes milk water (And milk would be echoed.) Link to comment https://forums.phpfreaks.com/topic/187974-most-repeated-data/ Share on other sites More sharing options...
Maq Posted January 11, 2010 Share Posted January 11, 2010 Something similar to: SELECT COUNT(food) cnt, food FROM [table_name] GROUP BY food, ORDER BY cnt DESC; If you only want the top one, which seems to be the case, append "LIMIT 1" to the query. Link to comment https://forums.phpfreaks.com/topic/187974-most-repeated-data/#findComment-992512 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.