Jump to content

Wondering if there's a better way (IN vs. JOIN)


KevinM1

Recommended Posts

I have a many-to-many relationship in a game review site I'm working on.  A review can be for a game that is available on several platforms (example: the Grand Theft Auto games), and each platform will have many reviews, one for each game reviewed on that platform.  So, to represent this relationship, I have a pivot table that holds the id for both reviews and platforms.  In other words, my setup is:

 

reviews:
int id,
varchar title,
text content,
etc.

platforms:
int id,
varchar name

platforms_reviews
int id,
int platform_id,
int review_id

 

To figure out what platforms a particular game review is for, I have the following query:

 

SELECT name FROM platforms WHERE id IN (SELECT platform_id FROM platforms_reviews WHERE review_id = {$review['id']})

 

I'm just wondering if there's a better way to do it, perhaps with a JOIN.

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.