dbTalk Databases Forums  

Help Need for a Query

comp.databases.oracle comp.databases.oracle


Discuss Help Need for a Query in the comp.databases.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Prabu Krishnan
 
Posts: n/a

Default Help Need for a Query - 06-28-2004 , 12:47 AM






Hi
Please Help me that I faced this Question in an interview but I cant
Get The Proper Answer from Any Where..

SQl> Select * from emp where rownum < 10;

Returns 9 Records BUT,

SQl> Select * from emp where rownum > 5;

Returns 0 Records

Why ? what is the Reason..

Please Help me.

Reply With Quote
  #2  
Old   
Vijai Kumar
 
Posts: n/a

Default Re: Help Need for a Query - 06-28-2004 , 06:44 AM






Hi,

rownum is a pseudo column.

When you say select * from emp where rownum < 10; it will select only
the first 9 rows from the total query output.
Each and every row returned will have the same rownum =1;

When you say select * from emp where rownum >1; it will not return any
rows beacuse every row has got rownum value = 1.

Try rownum=1 in the above query u will notice that all rows will be
returned.

There is also rowid feature try it out.

cheers
vijai

Reply With Quote
  #3  
Old   
Bent Stigsen
 
Posts: n/a

Default Re: Help Need for a Query - 06-28-2004 , 10:09 AM



Vijai Kumar wrote:
Quote:
Hi,

rownum is a pseudo column.

When you say select * from emp where rownum < 10; it will select only
the first 9 rows from the total query output.
Each and every row returned will have the same rownum =1;

When you say select * from emp where rownum >1; it will not return any
rows beacuse every row has got rownum value = 1.

Try rownum=1 in the above query u will notice that all rows will be
returned.
I think you mean "every *first* row". So if first row is filtered out
(like in the example), then every row will potentially be the first, and
therefore have rownum = 1, but not the second row.

/Bent


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.