Jump to content

Some sort of SQL JOIN


Mudsaf

Recommended Posts

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

This query should work

SELECT  first.*,  AVG(second.rating) AS ratingFROM firstJOIN second ON first.id = second.relatedGROUP BY second.rating
  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...