0

这适用于 player1name,但如何解决 player2name?

当我在这里时,如果您知道任何有用的可视化查询构建器,请告诉我;)


SELECT 
_game.player1,
_user.username AS player1name,
_game.player2,
_user.username AS player2name,
FROM _game
LEFT JOIN _user ON _game.player1 = _user.id

4

4 回答 4

1
SELECT player1,
_user.username AS player1name,
 player2,
_user2.username AS player2name
FROM _game
LEFT JOIN _user ON (_headsup.player1 = _user.id)
LEFT JOIN _user _user2 ON (_headsup.player2 = _user2.id)
于 2012-05-31T22:53:15.953 回答
1

我没有运行 ATM 的 mySQL,但它应该类似于...

SELECT 
player1,
u1.username AS player1name,
 player2,
u2.username AS player2name,
FROM _game
INNER JOIN _user u1 ON _headsup.player1 = u1.id
INNER JOIN _user u2 ON _headsup.player2 = u2.id

即连接上的别名,在选择中使用别名。

但是,我不知道 _headsup 来自哪里!

于 2012-05-31T22:54:18.377 回答
1
SELECT 
   player1,
   usr1.username AS player1name,
   player2,
   usr2.username AS player2name,
FROM _game
LEFT JOIN _user usr1 ON usr1.id= _game.player1
LEFT JOIN _user usr2 ON usr2.id= _game.player2
于 2012-05-31T22:57:27.820 回答
0

当您加入_gameON_user时,我认为您必须指定在这两个表上加入哪些字段。您指定加入,然后尝试加入_headsup_user

不确定player1player2是什么,但这些可能会出现模棱两可的字段,因为您没有说明它们来自哪个表。

所以先加入,然后用 on 进行第二_game次加入_user_user_headsup

FROM _game
LEFT JOIN _user ON _game.someField = _user.someField
JOIN _headsup ON _user.id = _headsup.player1
于 2012-05-31T22:56:19.197 回答