title: SQL error: Invalid identifier
body: <p>I am an SQL rookie and I would very much appreciate some assistance on this rather basic issue.</p>
  
  <pre><code>select comp_table.*
  from (select column_1,avg(column_2) as "avg"
        from table_1, group by column_1) comp_table
  </code></pre>
  
  <p>&rarr; returns correct records with 2 columns named <code>column_1</code> and <code>avg</code></p>
  
  <p>But if I change to:</p>
  
  <pre><code>select comp_table.avg
  from (select column_1,avg(column_2) as "avg"
        from table_1, group by column_1) comp_table
  </code></pre>
  
  <p>&rarr; returns <em>Error: Invalid identifier "avg"</em></p>
  
  <p>The thing is I only need to select the <code>avg</code> column, so I cannot do <code>select comp_table.*</code>. Can you guys please help?</p>
  
  <p>Also, if you could kindly provide some tuning tips for the query, that would be awesome.</p>