excessive34 excessive34 - 6 months ago 12
SQL Question

Multiple Select statements in one query - PHP + MySQL

Tables:
Players:
ID(PK), Name, Team, Pos

Matchups:
matchupID(PK), player1ID, player2ID

player1ID and 2 are FKs to Players.ID

I'd like to select the name of both players when pulling but cant get the query correct. I do NOT want a union here.

Something along the lines of this, I'm also open to a better suggestion for formatting the two tables I have.

$queryString = "SELECT Players.name FROM Players
INNER JOIN Matchup WHERE Players.ID = player1ID,
SELECT Players.name FROM Players
INNER JOIN Matchup WHERE Players.ID = player2ID";

Answer

You shoudl join two time Player and not matchup

  $queryString = "select a.name, b.name from Matchup as c
            Inner Join Players as a on c.player1ID = a.ID
            Inner Join Players as b on c.player2ID  = b.ID";