title: Subquery in PHP
body: <p>Let's put an easy example with two tables:</p>
  
  <pre><code>USERS (Id, Name, City)
  PLAYERS (Id_Player, Number, Team)
  </code></pre>
  
  <p>And I have to do a query with a subselect in a loop, where the subselect is always the same, so I would like to divide it into two queries and put the subselect outside the loop.</p>
  
  <p>I explain. <strong>What works but it is not optimize:</strong></p>
  
  <pre><code>for($i=0;$i&lt;something;$i++)
  {
      $res2=mysql_query("SELECT Team from PLAYERS WHERE Number=$i 
          AND Id_Player IN (SELECT Id FROM USERS WHERE City='London')");
  }
  </code></pre>
  
  <p><strong>What I would like to do but it doesn't work:</strong></p>
  
  <pre><code>$res1=mysql_query("SELECT Id from USERS where City='London'");
  for($i=0;$i&lt;something;$i++)
  {
      $res2=mysql_query("SELECT Team from PLAYERS WHERE Number=$i 
          AND Id_Player IN **$res1**");
  }
  </code></pre>
  
  <p>Thanks!</p>