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.) Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/187974-most-repeated-data/#findComment-992512 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.