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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.