here is a simple problem. I have a table of 500 rows and what to be able to select a given row number n. This is what I am doing:
select *
from table
where table.arg1 ='A'
and time_stamp=to_date('1/8/2010','MM/DD/YYYY')
and rownum = n
But it would only work for the row 1, for the rest it doesn’t return anything. Any idea?
The reason why
where rownum = 3returns an empty rowset is that the condition is not true for the first row. For the second row, there is still no first row in the resultset, andrownumis still1. So the condition fails again. See this page for a more detailed explanation.You can use
row_number()in a subquery:Or even simpler, but perhaps more confusing, using
rownumitself: