title: Is there a performance difference between CTE , Sub-Query, Temporary Table or Table Variable?
body: <p>In this excellent <a href="https://stackoverflow.com/questions/706972/difference-between-cte-and-subquery">SO question</a>, differences between <code>CTE</code> and <code>sub-queries</code> were discussed.</p>
  
  <p>I would like to specifically ask: </p>
  
  <p>In what circumstance is each of the following more efficient/faster?</p>
  
  <ul>
  <li>CTE</li>
  <li>Sub-Query</li>
  <li>Temporary Table</li>
  <li>Table Variable</li>
  </ul>
  
  <p>Traditionally, I've used lots of <code>temp tables</code> in developing <code>stored procedures</code> - as they seem more readable than lots of intertwined sub-queries.</p>
  
  <p><code>Non-recursive CTE</code>s encapsulate sets of data very well, and are very readable, but are there specific circumstances where one can say they will always perform better? or is it a case of having to always fiddle around with the different options to find the most efficient solution?</p>
  
  <hr>
  
  <p><strong>EDIT</strong>  </p>
  
  <p>I've recently been told that in terms of efficiency, temporary tables are a good first choice as they have an associated histogram i.e. statistics.</p>