rocoso Posted November 3, 2007 Share Posted November 3, 2007 Im trying to get the TOP 10 results of the rating_id. This sort of works but i get double results from rating_id. "SELECT rating_id, rating_num FROM ratings GROUP BY rating_id ORDER BY rating_num DESC LIMIT 10" this is the table CREATE TABLE `ratings` ( `id` int(11) NOT NULL auto_increment, `rating_id` int(11) NOT NULL, `rating_num` int(11) NOT NULL, `IP` varchar(25) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ID rating_id rating_num IP 1 345 5 192.168.1.7 2 123 3 192.168.1.7 3 345 3 192.168.1.7 Ive tried variations of counting rating_id, just cant seem to figure it out. Im new to this... Quote Link to comment https://forums.phpfreaks.com/topic/75930-solved-select-top-10-rating/ Share on other sites More sharing options...
Barand Posted November 3, 2007 Share Posted November 3, 2007 Sort them by the average rating num for each rating id SELECT rating_id, AVG(rating_num) as rating GROUP BY rating_id ORDER BY rating DESC LIMIT 10 Quote Link to comment https://forums.phpfreaks.com/topic/75930-solved-select-top-10-rating/#findComment-384345 Share on other sites More sharing options...
rocoso Posted November 3, 2007 Author Share Posted November 3, 2007 SELECT rating_id, AVG(rating_num) as rating FROM ratings GROUP BY rating_id ORDER BY rating DESC LIMIT 10 I added the FROM ratings. It seems to be working YEAHHH ! thanks Quote Link to comment https://forums.phpfreaks.com/topic/75930-solved-select-top-10-rating/#findComment-384346 Share on other sites More sharing options...
Barand Posted November 3, 2007 Share Posted November 3, 2007 I added the FROM ratings. Oops! Quote Link to comment https://forums.phpfreaks.com/topic/75930-solved-select-top-10-rating/#findComment-384348 Share on other sites More sharing options...
rocoso Posted November 3, 2007 Author Share Posted November 3, 2007 YOU ARE A GENIUS!!! thanks Quote Link to comment https://forums.phpfreaks.com/topic/75930-solved-select-top-10-rating/#findComment-384353 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.