MySQL: How to pull information from multiple tables based on information in other tables?

Posted by Greg on Stack Overflow See other posts from Stack Overflow or by Greg
Published on 2011-01-09T20:35:27Z Indexed on 2011/01/09 20:53 UTC
Read the original article Hit count: 222

Filed under:
|

Ok, I have 5 tables which I need to pull information from based on one variable.

gameinfo
id | name | platforminfoid

gamerinfo
id | name | contact | tag

platforminfo
id | name | abbreviation

rosterinfo
id | name | gameinfoid

rosters
id | gamerinfoid | rosterinfoid

The 1 variable would be gamerinfo.id, which would then pull all relevant data from gamerinfo, which would pull all relevant data from rosters, which would pull all relevant data from rosterinfo, which would pull all relevant data from gameinfo, which would then pull all relevant data from platforminfo.

Basically it breaks down like this:

  • gamerinfo contains the gamers basic information.
  • rosterinfo contains basic information about the rosters (ie name and the game the roster is aimed towards)
  • rosters contains the actual link from the gamer to the different rosters (gamers can be on multiple rosters)
  • gameinfo contains basic information about the games (ie name and platform)
  • platform info contains information about the different platforms the games are played on (it is possible for a game to be played on multiple platforms)

I am pretty new to SQL queries involving JOINs and UNIONs and such, usually I would just break it up into multiple queries but I thought there has to be a better way, so after looking around the net, I couldn't find (or maybe I just couldn't understand what I was looking at) what I was looking for. If anyone can point me in the right direction I would be most grateful.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about joins