0

我有三张桌子:

players
------
id|name 

teams
-------
id|name 

teams_players
-------------
id|teamID|playerID

我现在想从表“players”中获取每个条目,其中 player.id 例如在 id 为 15 的团队中。换句话说:我想获取属于特定团队的每个玩家(例如 teamID=15)

我尝试加入但失败了。

这是我到目前为止得到的:

       "SELECT players.*
        FROM players
        JOIN teams_players
        ON teams_players.teamID = 15 
        GROUP BY players.id"; 
4

2 回答 2

2

你太复杂了。

select players.*
 from players
 join teams_players
 on players.id = teams_players.playerid
 where teams_players.teamid = 15

JOIN部分与数字 15 无关。15 是您过滤结果的方式。

于 2013-07-15T19:09:58.217 回答
0

您可以在多个条件下加入您的表格,而且您没有在on子句中提及您的表格之间的关系

SELECT players.*
        FROM players
        JOIN teams_players
        ON (players.id = teams_players.playerid AND teams_players.teamID = 15 )
        GROUP BY players.id
于 2013-07-15T19:14:01.323 回答