Reference alias in subquery
<p>Let's say there's a <code>person</code> table with the columns <code>name</code> and <code>age</code>.</p>

<p>I'm writing a DSL that generates the following SQL:</p>

<pre><code>select *
  from (select * from person p1 inner join person p2 on p1.name = p2.name) as pj;
</code></pre>

<p>Now, I would like to be able to access <code>p1</code> and <code>p2</code> in the outer query, like this:</p>

<pre><code>select *
  from (select * from person p1 inner join person p2 on p1.name = p2.name) as pj
  where p1.name = 'xxx'; &lt;-- DOESN'T WORK
</code></pre>

<p>Something like <code>pj.p1.name</code> would be ideal. Is there a way to achieve this if I don't know the exact column names of <code>person</code>?</p>