Jump to content

JOIN help


moon 111

Recommended Posts

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
Share on other sites

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
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.