Note that there are some explanatory texts on larger screens.

plurals
  1. POMySql find friends of Player X from table Games
    text
    copied!<p>1) I need to: <strong>"Find All players that play the same game of Player '55' for games' id bigger than 2"</strong></p> <p>The tables are as in the picture below:</p> <p><img src="https://i.stack.imgur.com/jV2Hq.png" alt="enter image description here"></p> <p>I tried many statements but they produce wrong result:</p> <pre><code>SELECT Games.id, Players.id from Games, Players WHERE Players.id='55' and Games.id &gt; 2; </code></pre> <p>2) Additionally what would you do if I say that I need to select the same as before, where the "<strong>Game's id are only the last 2 in Descending order</strong>" (i.e. only games with id 3 and 4 in this case, but that could be different for other cases). I can only think of comparing Games.id with a number from user input, but some of you might know another way...</p> <p>Can someone help me please? Thank you!</p> <p><strong>EDIT</strong>:</p> <p>1) <code>SELECT b.id_player, b.id_game FROM Players a, Players b WHERE a.id_player = '55' AND b.id_game = a.id_game AND b.id_player &lt;&gt; '55' AND a.id_game &gt; 2;</code></p> <p>2) Option 1 works for question 1, but question 2 would require a TOP clause which doesn't work for me. </p> <p>How can I use LIMIT or TOP to achieve the same as <code>a.id_game &gt; 2</code>? I want only the results from the last 2 ID_GAMEs, in this case are id=3 and id=4...</p> <p><strong>EDIT:</strong> Well never mind, I've got the 1st question. I will just put LIMIT to a fixed number. Thanks for the help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload