title: Mysql - Pass Variable to Subquery From Clause
body: <p>I have the following query that I am working on, you'll find sample data <strong><a href="https://www.db-fiddle.com/f/35EQE2yzdxNs3KHZnQkMuQ/2" rel="nofollow noreferrer">on this db fiddle</a></strong> :</p>
  
  <pre><code>SET @count=0; 
  SELECT ( @rank := IF(@points = points, @rank + 1, IF(@points := points, @rank + 1, @rank + 1)) ) AS rank,
         er.* 
  FROM (SELECT cc6_MensLeague_players.id AS `id`, 
               ( 1288 ) AS points, 
               (SELECT Max(@count := IF(outcome = 2, @count + 1, 0)) AS max_consecutive_wins 
                FROM (SELECT * 
                      FROM cc6_MensLeague_rounds 
                      WHERE player = 785 
                      ORDER BY date ASC) AS temp
                ) AS `maxcon` 
        FROM cc6_MensLeague_players 
        GROUP BY `id`) er 
  CROSS JOIN (SELECT @rank := 0, @points := -1) params 
  ORDER BY id DESC; 
  </code></pre>
  
  <p>This code works perfect (thanks to Tobias Thornfeldt Nissen) but what I'm now trying to do is make the player id (785) dynamic... I can't seem to pass my id variable (cc6_MensLeague_players.id) to the subquery from clause.</p>
  
  <p>I have tried the following methods:</p>
  
  <ol>
  <li><p>Adding <code>@id :=</code> to the beginning of <code>... cc6_mensleague_players.id AS id ...</code> and changing <code>... WHERE player = 785 ...</code> to <code>... WHERE player = @id ...</code> NO LUCK!</p></li>
  <li><p>Changing <code>... player = 785 ORDER BY DATE ASC ...</code> to <code>... player = @id GROUP BY ID ORDER BY DATE ASC ...</code> NO LUCK!</p></li>
  <li><p>I have also tried a few other tactics but I just can't figure it out.</p></li>
  </ol>
  
  <p>So my question is:
  How do I make <code>WHERE player = cc6_mensleague_players.id</code> (line 9) work?</p>
  
  <p>If you can point me in the right direction it would be greatly appreciated.</p>
  
  <p>Thanks.</p>