简体   繁体   中英

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 can't 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";

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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM