title: Inner query aliasing in a correlated subquery
body: <p>So my understanding is that an inner query runs before an outer query. I was watching a PluralSight course on Postgresql and it was talking about correlated subqueries and I am confused. So say I have the following query:</p>
  <pre><code>SELECT a.flight_date,
         a.departure_delay_time,
         a.origin
  FROM allflights a
  WHERE a.flight_date = &quot;2010-01-02&quot;
  AND a.origin = 'DEN'
  AND a.departure_delay_time &gt; (SELECT AVG(departure_delay_time)
                                 FROM allflights
                                WHERE departure_delay_time &gt; 0
                                  AND a.origin = origin);
  </code></pre>
  <p>Now if the inner query is</p>
  <pre><code>SELECT AVG(departure_delay_time)
    FROM allflights
   WHERE departure_delay_time &gt; 0
     AND a.origin = origin);
  </code></pre>
  <p>Then how does it know that a is the alias for allflights?</p>