我有一个游戏,桌子看起来像:
// users
user_id | favorite_color
// games
game_id | game_name
// game_participants
id | fk_game_id | fk_user_id
我想在特定游戏中获得所有用户最喜欢的颜色。我可以通过几个步骤来做到这一点,例如:
// get the game.
Game game = select * from games where game_id = 'abc';
// get each user's favorite color, one at a time.
for (participants in game) {
select favorite_color from users where user_id = game.participants[i].id;
}
但是有没有办法在一个选择语句中做到这一点?
谢谢