Using ROW_NUMBER() function in WHERE clause

To get around this issue, wrap your select statement in a CTE, and then you can query against the CTE and use the windowed function’s results in the where clause.

    select   employee_id,
             RowNum = row_number() OVER ( order by employee_id )
    from     V_EMPLOYEE 
    ORDER BY Employee_ID
SELECT  employee_id
FROM    MyCte
WHERE   RowNum > 0

Leave a Comment