我有这两张桌子。我有当前玩家 id_player,我想从这个玩家 (id_player) 和他的对手信息中选择所有游戏。当前玩家和对手玩家连接到相同的 id_game。或者
table game:`id_game` (...)
table game_player:`id_game_player, id_player, id_game`(...)
“给我所有与当前玩家和他的对手分开的游戏信息,并加入他们游戏的信息(按游戏分组)”
结果为:
+---player game info
game1 |
+---opponent game info
+---player game info
game2 |
+---opponent1 game info
+---player game info
game2 |
+---opponent2 game info
谁能为我提供 MySQL 解决方案?
谢谢
编辑:我尝试使用此代码,但我不确定这是最快的方式(在哪里),有没有办法像上面那样对结果进行分组?
SELECT * FROM game_player
JOIN `game` ON game.id_game = game_player.id_game
WHERE game_player.id_game
IN (
SELECT game_player.id_game
FROM `game_player`
WHERE game_player.id_player =2)