Skip to content
Advertisement

Joining player and game tables to get player points

I have the following SQL tables and I’m basically trying to pull a table of every game that Ralph played in for 2018, and the amount of points scored.

Ralph has a unique_id, but may play on multiple teams, or in different positions. Each year that he plays has a new record entered into the player info table for each of those teams and/or positions.

The games data table’s player ID may use both of Ralph’s player info records, so for instance, records 1 and 2 of game data are both for Ralph, and his actual total points scored is 18 (12 + 6). I don’t need those points to be added together, as that can be done easier in PHP, but I do need both records pulled.

The table should show pi.id, pi.unique_id, gi.id, gd.* WHERE gd.player_id = Any of Ralph’s pi.id’s AND pi.year=2018

Any help here is appreciated, this seems a bit out of my wheelhouse.

Advertisement

Answer

Join the tables like this:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement