I have a table and I need to retrieve the ID of the Second row. How to achieve that ?
By Top 2
I select the two first rows, but I need only
you can use OFFSET
and FETCH NEXT
SELECT id
FROM tablename
ORDER BY column
OFFSET 1 ROWS
FETCH NEXT 1 ROWS ONLY;
NOTE:
OFFSET can only be used with ORDER BY clause. It cannot be used on its own.
OFFSET value must be greater than or equal to zero. It cannot be negative, else return error.
The OFFSET argument is used to identify the starting point to return rows from a result set. Basically, it exclude the first set of records.
The FETCH argument is used to return a set of number of rows. FETCH can’t be used itself, it is used in conjuction with OFFSET.