What is the function of rownum in the database?

In certain databases, rownum is a pseudocolumn that represents the row number in the query results. It can be used to limit the number of rows in the query result set or filter specific rows.

“Rownum can be used with a where clause to limit the number of rows in a query result set. For example, using select * from table where rownum <= 10 can return the first 10 records from the table."

You can also use rownum in conjunction with the order by clause to filter specific rows. For example, selecting * from table where rownum = 1 order by column can return the first row record in table sorted by the column column.

It is important to note that rownum is allocated after the query results are returned, not during the query process. Therefore, if a subquery is nested in the query statement, the row number of rownum may not be assigned in the expected order.

bannerAds