Monday, 15 February 2010

sql - MySql find friends of Player X from table Games -



sql - MySql find friends of Player X from table Games -

1) need to: "find players play same game of player '55' games' id bigger 2"

the tables in image below:

i tried many statements produce wrong result:

select games.id, players.id games, players players.id='55' , games.id > 2;

2) additionally if need select same before, "game's id lastly 2 in descending order" (i.e. games id 3 , 4 in case, different other cases). can think of comparing games.id number user input, of might know way...

can help me please? give thanks you!

edit:

1) select b.id_player, b.id_game players a, players b a.id_player = '55' , b.id_game = a.id_game , b.id_player <> '55' , a.id_game > 2;

2) alternative 1 works question 1, question 2 require top clause doesn't work me.

how can utilize limit or top accomplish same a.id_game > 2? want results lastly 2 id_games, in case id=3 , id=4...

edit: never mind, i've got 1st question. set limit fixed number. help

you need self-join. can't test right - sql fiddle in moment, should like:

select b.id_player, b.id_game players a, players b a.id_player = '55' , b.id_game = a.id_game , b.id_player <> '55' , a.id_game > 2 order b.id_game limit 2;

mysql sql logic

No comments:

Post a Comment