Monday, March 19, 2012

Finding Nth row in SQL Server

Finding nth row in SQL Server. Here is the simple query using ROW_NUMBER() function. In below example I am finding the 2 row:
SELECT * FROM
    (SELECT ROW_NUMBER()
        OVER (ORDER BY id) AS Row,
        id
    FROM Table) AS EMP
WHERE Row = 2

Enjoy!!!!!!

1 comment:

  1. SELECT * FROM
    (SELECT ROW_NUMBER()
    OVER (ORDER BY eno) AS Row,
    *
    FROM emp10) AS EMP
    WHERE Row = (select count(*) from emp)

    ReplyDelete