Home » RDBMS Server » Server Administration » rownum
rownum [message #373209] Wed, 04 April 2001 08:26 Go to next message
adelia
Messages: 45
Registered: April 2001
Member
What rownum does ?

select * from emp
where rownum < 10
order by hiredate desc
---
Re: rownum [message #373212 is a reply to message #373209] Wed, 04 April 2001 08:33 Go to previous messageGo to next message
Prem
Messages: 79
Registered: August 1998
Member
adelia,

the above select will pick 10 records randomly and then order it by hiredate. i.e. it will perform the where condition first and then, on the result, perform the sorting.

hth

Prem :)
Re: rownum [message #373214 is a reply to message #373209] Wed, 04 April 2001 09:45 Go to previous messageGo to next message
Krishnan
Messages: 18
Registered: October 2000
Junior Member
Rownum is performed prior to order by and hence you will only see those records that ordered and has their rownum <10. You may probably see no records or less than 10 records
Re: rownum [message #373248 is a reply to message #373209] Thu, 05 April 2001 23:38 Go to previous messageGo to next message
Naresh
Messages: 27
Registered: March 2001
Junior Member
Hi Adelia,

The ROWNUM is a PSEUDOCOLUMN which returns a number indicating the order in which Oracle selects the row from a table. The first row selected has a ROWNUM of 1, the second has 2, and so on.

You can use ROWNUM to limit the number of rows returned by a query.

You can also use ROWNUM to assign unique values to each row of a table, as in this example:

UPDATE tabx
SET col1 = ROWNUM;

----------------------------

HTH

Naresh
Re: rownum [message #373747 is a reply to message #373209] Thu, 03 May 2001 23:53 Go to previous messageGo to next message
Sachin
Messages: 52
Registered: May 2001
Member
Why this query is not working.
select * from emp where rownum>2;
It returns no rows are selected.
Re: rownum [message #373751 is a reply to message #373209] Fri, 04 May 2001 07:07 Go to previous message
Naresh Sharma
Messages: 12
Registered: April 2001
Junior Member
Hi Sachin,

ROWNUM uses a function called COUNT STOPKEY.

This means that you can only use < OR = sign with rownum.

HTH

Naresh
Previous Topic: SQL Query Problem
Next Topic: Help w/study questions
Goto Forum:
  


Current Time: Sat Jun 29 00:05:02 CDT 2024