这适用于 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
这适用于 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
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)
我没有运行 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 来自哪里!
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
当您加入_game
ON_user
时,我认为您必须指定在这两个表上加入哪些字段。您指定加入,然后尝试加入_headsup
和_user
。
不确定player1
和player2
是什么,但这些可能会出现模棱两可的字段,因为您没有说明它们来自哪个表。
所以先加入,然后用 on 进行第二_game
次加入_user
_user
_headsup
FROM _game
LEFT JOIN _user ON _game.someField = _user.someField
JOIN _headsup ON _user.id = _headsup.player1