Just trying to optimize a SQL Query.
SELECT Code, COUNT(*)
FROM tblData
WHERE ListID = 380
GROUP BY Code
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:
SELECT a.Code, COUNT(*)
FROM ( SELECT *
FROM tblData
WHERE ListID = 380
) a
GROUP BY a.Code
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?
With any decent query optimizer, the two queries should boil down to the exact same operations. So I’m not surprised you find they run in the same time.
I don’t think you can modify your query to make it run any faster. What you can do, of course, is to have an index on
ListID– but I expect you have that already.