Kingskin Posted October 20, 2005 Share Posted October 20, 2005 Hi, My db table (episode_result) has these columns: player_id position I'm trying to find which player_id occurs most often where position = 1. Eg, if i've got: player_id | position | Bill | 1 Bill | 1 Ben | 1 Bill | 3 Ben | 2 Bill | 1 I want to return 'Bill' I've got this code: SELECT TOP 1 player_id FROM (SELECT COUNT(*) AS myNewColumn, player_id FROM episode_result WHERE position = 1 GROUP BY player_id) DERIVEDTBL ORDER BY myNewColumn DESC"; But unfortunately it doesn't work. Can anyone help me out with this please? Link to comment https://forums.phpfreaks.com/topic/2701-get-most-frequent-data-in-column/ Share on other sites More sharing options...
Kingskin Posted October 22, 2005 Author Share Posted October 22, 2005 Anyone? Link to comment https://forums.phpfreaks.com/topic/2701-get-most-frequent-data-in-column/#findComment-9046 Share on other sites More sharing options...
ryanlwh Posted October 22, 2005 Share Posted October 22, 2005 untested [!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] COUNT(position) AS myNewColumn, player_id FROM episode_result WHERE position = 1 GROUP BY player_id ORDER BY myNewColumn DESC LIMIT 1 [!--sql2--][/div][!--sql3--] Link to comment https://forums.phpfreaks.com/topic/2701-get-most-frequent-data-in-column/#findComment-9047 Share on other sites More sharing options...
Kingskin Posted October 22, 2005 Author Share Posted October 22, 2005 Worked a treat, thanks mate :-) Link to comment https://forums.phpfreaks.com/topic/2701-get-most-frequent-data-in-column/#findComment-9048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.