moon 111 Posted March 28, 2008 Share Posted March 28, 2008 Would something like this work? (there is also a row rating.) SELECT * FROM site AS s, rating AS r WHERE s.id = r.sid ORDER BY AVG(r.rating) DESC Link to comment https://forums.phpfreaks.com/topic/98275-join-help/ Share on other sites More sharing options...
moon 111 Posted March 28, 2008 Author Share Posted March 28, 2008 I'll be more specific: I have a table 'site' that has information such as id, title, url etc. I have another table 'rating' which has the cols sid, uid, rating. sid reffers to the site that was rated. How can I order the information in the table 'site' by the average rating of all the rows where the sid (in rating) equals id (in site)? Link to comment https://forums.phpfreaks.com/topic/98275-join-help/#findComment-502872 Share on other sites More sharing options...
aschk Posted March 28, 2008 Share Posted March 28, 2008 So, to break it down. You need: The average rating for each site, and then have the sites ordered by their average rating SELECT s.id as 'site_id' ,AVG(r.rating) as 'average_rating' FROM site s JOIN rating r ON s.id = r.sid GROUP BY s.id ORDER BY average_rating DESC Link to comment https://forums.phpfreaks.com/topic/98275-join-help/#findComment-502966 Share on other sites More sharing options...
fenway Posted March 28, 2008 Share Posted March 28, 2008 This is very clearly a double-post -- topic locked. Link to comment https://forums.phpfreaks.com/topic/98275-join-help/#findComment-503612 Share on other sites More sharing options...
Recommended Posts