Mudsaf Posted June 1, 2015 Share Posted June 1, 2015 Hello, i'm currently facing problem where i have 2 tables like this. I have no clue how to make this happen, would appreciate any help example links for guide or solutions. //First ------- id | name | stuff 1 - Test - bla //Example values 2 - Test2 - Bla2 ------- //Second ------- id | related | rating 1 - 2 - 5 //Example values 2 - 2 - 1 3 - 2 - 2 So i'm trying to do SQL query where i can select * data from first table, and join on second table with AVG(rating) where related (second table) = id(first table). Link to comment Share on other sites More sharing options...
Ingolme Posted June 1, 2015 Share Posted June 1, 2015 This query should work SELECT first.*, AVG(second.rating) AS ratingFROM firstJOIN second ON first.id = second.relatedGROUP BY second.rating 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now