Jump to content

JOIN 3 SQL SELECT together


MPVM

Recommended Posts

Hi PHP Freaks!

 

I have a problem joining 3 mysql tables together

 

my tables are:

 

games

- id

- name

 

category

- id

- cat

 

rating

- id

- rating

 

I want to merge them together so i can get:

 

- id

- name

- cat

- rating

 

The rating should be used with the AVG function during the JOIN

 

 

I've tried a lot myself but can not make i work

Can somebody write a SQL query that will work?

 

Thanks in advance!

MPVM

Link to comment
https://forums.phpfreaks.com/topic/170533-join-3-sql-select-together/
Share on other sites

games

------

id

cat_id

name

 

category

--------

id

cat

 

rating

-----

game_id

rating

count

 

SELECT games.name, category.*, rating.rating, rating.count
FROM games
LEFT JOIN category ON games.cat_id = category.id
LEFT JOIN rating ON games.id = rating.game_id

Archived

This topic is now archived and is 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.