0

This question already has an answer here:

I'm having a table 'Products' and if Execute this query

SELECT TOP 1000 [ProductID]
      ,[ProductDesc]
      ,[ManufacturingDate]
      ,[ExpiryDate]
      ,[Price]
  FROM [TestSat].[dbo].[Products]

I got the output:

enter image description here

and If I use this select query:

SELECT ProductDesc,Price
  FROM [Products]
  WHERE Price>20.00

I got this output:

enter image description here

If I use CTE-Select like this:

 ;WITH ProductsCTE(ProdName,Price) AS
( SELECT ProductDesc,Price
  FROM [Products]
  WHERE Price>20.00
)

I got this output:

enter image description here

The only difference I found between this simple Select Query as well as CTE Select query is the Column name (ProductDesc as ProdName). Does it is the only difference between normal Select query as well as CTE Select query?

marked as duplicate by Colin 't Hart, Philᵀᴹ, Paul White, RLF, ypercubeᵀᴹ Mar 10 '15 at 13:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Did you tried checking execution plan. CTE is kind of temp table and for moment you are storing a part of data in it and then selecting the data. – Shanky Mar 10 '15 at 7:23
  • 2
    Weird question, IMHO, have you searched a bit about what is a CTE, how it works and how can be used? And I mean on SE site, not even using your prefered search engine for a global search. Look for CTE vs temp tables, CTE vs subquery, CTE recursive, CTE performance, How CTE really works?. – Yaroslav Mar 10 '15 at 8:26

Browse other questions tagged or ask your own question.