Is there a way to output a query from the Nth line in MS-SQL? For example, that the request would give everything from the table except for the first two lines.
- And what server? since 2012 there is an OFFSET. Prior to this, number row_number () entries and select according to the condition - Mike
- I use server 2008. row_number () is exactly what I use. But my heart feels that there is a more direct way. - ArtemiyMVC
|
1 answer
For this, you can use ORDER BY ... OFFSET ...
(available from SqlServer 2012 and later):
select A, B, C from TableName order by ColumnName offset 2 rows
In SqlServer 2008 for this purpose, you can use the ROW_NUMBER
function:
;with t as ( select A, B, C, row_num = row_number() over (order by ColumnName) from TableName ) select A, B, C from t where row_num > 2 order by row_num;
- offset does not work in mssql 2008. - ArtemiyMVC
|