I have three tables :
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)
I have created a stored procedure that returns the number of points scored by a player based on their surname.
CREATE PROCEDURE getpoints @surname nvarchar(30)
AS
SELECT forename, surname, points
FROM videogames.cod
WHERE surname = @surname
GO
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.
Forename, surname, points, wins, losses, gametype.
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.