一个查询中的多个Select语句 - PHP + MySQL

时间:2016-05-25 20:31:41

标签: php mysql

表: 玩家: ID(PK),姓名,团队,职位

,对位: matchupID(PK),player1ID,player2ID
player1ID和2是Players.ID的FK

我想在拉动时选择两个玩家的名字,但无法正确查询。我不想在这里建立工会。

根据这一点,我也可以更好地建议格式化我拥有的两张桌子。

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

1 个答案:

答案 0 :(得分:1)

你应该加入两次球员而不是比赛

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