title: How to get a specific column value from current row in mysql?
body: <p>How can I get the value of a specific column in the current row? Let's say we have a table &quot;games&quot; with columns &quot;gameid&quot; and &quot;game_type&quot;. Each game has multiple winners (one user can win any number of times). Now let's assume we have another table &quot;game_winners&quot; which keeps track of all the game-winners and has &quot;gameid&quot;, &quot;userid&quot;. What I want to achieve is get the number of unique winners in a particular game. The query I need would look something like this:</p>
  <pre><code>select gameid, game_type, (
    select count(distinct(userid)) 
    from games 
    join winners 
    where gameid = {gameid of current row}
  ) as game_winners 
  from games 
  join winners 
  </code></pre>
  <p>I'm not sure how to get the gameid from the current row and pass it into the where clause.</p>
  <p>Any help is very much appreciated.</p>