Monday, October 27, 2014

Is it possible to nest SELECT statements?



;with mycte as (SELECT *
,ROW_NUMBER() OVER(ORDER BY OrderID DESC ) RN40
FROM dbo.Orders)
,mycte1 as (
select *
,ROW_NUMBER() OVER(ORDER BY OrderID ASC ) RN20
from mycte
WHERE RN40 <=40)
Select * from mycte1
WHERE RN20<=20




No comments:

Post a Comment