Select subset of rows using Row_Number()
Select id, name, ROW_NUMBER() OVER (ORDER BY id asc) as 'RowNo' from customers where RowNo between 50 AND 60 I am trying to select a subset of rows between 50 and 60 . The problem is 'RowNo' is an invalid column name. Thank you Using SQL SERVER 2008 R2 Michał Powaga Use your query as subquery like bellow: select * from ( Select id, name, ROW_NUMBER() OVER (ORDER BY id asc) as [RowNo] from customers ) t where RowNo between 50 AND 60 You can use CTE as well but whether to choose one over another read Difference between CTE and SubQuery? and check execution plan. You need to do something like