Is
select id from (select * from employee
) as t
is same as
;with temp as (select * from employee)
select id from temp
?????
Both will return same result.But regarding performance oriented.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, in your example they are the same, you should view the execution plan to see any differences in how they work and hence performance. If you ‘include execution plan’ in SSMS and execute both queries in one batch, you will get a ‘Query cost (relevant to the batch)’ which will tell you which query performs better. I would guess that they are equivalent.
The advantage of a CTE (your second statement) over a derived table is that they can reference themselves and be used for recursion.