How to retrieve third row from any table using "rownum" key word ( i am using oracle-10g)
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
Oracle assigns values to ROWNUM sequentially as rows are produced by the query - thus, the first row fetched gets ROWNUM=1, the second row fetched gets ROWNUM=2, the third row fetched gets ROWNUM=3, etc. Notice - for a row to be assigned ROWNUM=3 two preceding rows MUST be fetched. And this is why your query returns no rows. You're asking the database for the third row fetched - but rows 1 and 2 have never been fetched.
To demonstrate, try running the following queries:
To work around your problem, try the following:
Share and enjoy.
You would need to do something like this
rownum
is not assigned until after the predicate phase sorownum = 3
will always be false. Use a CTE or derived table then you can access therownum
from outside it.This is incorrect. This will always return '3', because you are selecting ROW_NUMBER.
It should instead be "select *", as mentioned below:
Is rownum an actual column in your salary table? If not, depending on your DB type, rownum is likely not supported.