title: SQL Stored Procedure - Columns From Three Tables?
body: <p>I have three tables :</p>
  
  <pre><code>videogames.cod - playerid (PK), forename, surname, points
  videogames.codhost - hostid (PK), playerid (FK), gameid (FK), wins (integer), losses (integer)
  videogames.codgame - gameid (PK), gametype (extinction, deathmatch) 
  </code></pre>
  
  <p>I have created a stored procedure that returns the number of points scored by a player based on their surname. </p>
  
  <pre><code>CREATE PROCEDURE getpoints @surname nvarchar(30)
  AS
  SELECT forename, surname, points
  FROM videogames.cod
  WHERE surname = @surname
  GO
  </code></pre>
  
  <p>The problem is I also want data from two other tables. I need the wins and losses from the codhost table, which are both integers, and I want the gametype from the codgame table i.e.</p>
  
  <p>Forename, surname, points, wins, losses, gametype.</p>
  
  <p>I know I need a join but I don't know what to join the tables on as they don't all share the same key. Yes I know I could change the fields in the tables but I would prefer to learn how to do this for future references and it makes more sense to me when I use things I understand - like games for example. Iknow it's dumb but it's how I learn.</p>