title: Optimizing a GROUP BY query
body: <p>Just trying to optimize a SQL Query.</p>
  
  <pre><code>SELECT   Code, COUNT(*) 
  FROM     tblData 
  WHERE    ListID = 380 
  GROUP BY Code
  </code></pre>
  
  <p>The table contains 10 million records. So the query usually take 4-5 secs to find the record on SQL SERVER 2008 R2. I found another way of expressing it:</p>
  
  <pre><code>SELECT a.Code, COUNT(*) 
  FROM   (  SELECT * 
            FROM   tblData 
            WHERE  ListID = 380 
         ) a 
  GROUP BY a.Code
  </code></pre>
  
  <p>Though in my tests it produce the results in the exact same time. But I wonder if this is faster the previous one or visa versa. Any idea?</p>