title: basic sql server subquery, how it impact performance?
body: <p>Do this SQL query has a performance penalty?</p>
  
  <blockquote>
    <p>select fullname, address from (select  (name + ' ' + lastname) as fullname, address from mytable) as tab</p>
  </blockquote>
  
  <p>Compare with:</p>
  
  <blockquote>
    <p>select  (name + ' ' + lastname) as fullname, address from mytable</p>
  </blockquote>
  
  <p>Maybe you think.. Why I want to do this, the reason is because SQL Server not allow to use alias in group by, so usign subquery I can do this</p>
  
  <blockquote>
    <p>select fullname, address from (select  (name + ' ' + lastname) as fullname, address from mytable) as tab group by fullname</p>
  </blockquote>
  
  <p>Instead of</p>
  
  <blockquote>
    <p>select  (name + ' ' + lastname) as fullname, address from mytable group by name + ' ' + lastname</p>
  </blockquote>
  
  <p>This is just an example, where alias is and alias of a basic concatenation, but something concatenation are more complex and rewrite it into group clause is really ugly.</p>