title: Unknown column in field list - Subquery not finding parent variable
body: <p>The following query</p>
  
  <pre><code>SELECT
  LocationID,
  a.Country,
  ISO2,
  Region1,
  Region2,
  Region3,
  Area1,
  a.City,
  a.ZIP,
  a.Lat,
  a.Lng
  FROM AWE_Locations a,
  (SELECT PropVidID,
      Latitude,
      Longatude,
  SQRT(POW(69.1 * (Latitude - a.Lat), 2) + POW(69.1 * (a.Lng - Longatude) * COS(Latitude / 57.3), 2)) AS Distance FROM AWE_Propvids c
  )
  as x
  
  WHERE
  a.ZIP  LIKE '9021%' and
  a.Country = 'US'
  
  HAVING
  x.Distance &lt;= '100'
  
  ORDER BY
  a.Country,
  Region1,
  Region2,
  a.city,
  ISO2,
  a.zip
  
  ASC Limit 15
  </code></pre>
  
  <p>returns the error:</p>
  
  <pre><code>#1054 - Unknown column 'a.Lat' in 'field list'
  </code></pre>
  
  <p>Why cant the subquery use the variable from the parent query in this case?
  I have tried various combinations to try and fix this, but have had no luck so far.</p>