title: Accessing parent column info in a sub query
body: <p>I am trying to write a sub query to have in a larger query, The subquery I am writting needs to get a.workorder_id from the main column </p>
  
  <p>This one works ( Notice x.workorder_id = '805' )</p>
  
  <pre><code>SELECT a.* , 
  ( SELECT SUM( maxes ) qty 
    FROM  ( 
       SELECT MAX( qty ) maxes 
       FROM `rework_line` x 
       WHERE x.workorder_id = '805' 
       GROUP BY x.size 
    ) as tba 
  ) tmpsum 
  FROM rework_line a 
  WHERE a.workorder_id = '805' 
  GROUP BY a.workorder_id
  </code></pre>
  
  <p>Yet when I change x.workorder_id = a.workorder_id it no longer works and tells me</p>
  
  <p><strong>#1054 - Unknown column 'a.workorder_id' in 'where clause'</strong></p>
  
  <pre><code>SELECT a.* , 
  ( SELECT SUM( maxes ) 
    qty FROM  ( 
       SELECT MAX( qty ) maxes 
       FROM `mtborah_rework_line` x 
       WHERE x.workorder_id = a.workorder_id 
       GROUP BY x.size 
    ) as tba 
  ) tmpsum 
  FROM mtborah_rework_line a 
  WHERE a.workorder_id = '805' 
  GROUP BY a.workorder_id
  </code></pre>
  
  <p>I am sure it is something simple I forgot, but in all my googing I can not find out how to do it, I also tryed asking in the mysql room on freenode, and all they would say is to rewrite it as a join, which is not possible due to the query I am having it in If I re-join to this table it will through off my counts and sum's</p>