dbTalk Databases Forums  

ROWNUM with WHERE clause

comp.database.oracle comp.database.oracle


Discuss ROWNUM with WHERE clause in the comp.database.oracle forum.



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

Default ROWNUM with WHERE clause - 03-14-2005 , 08:42 AM






Hi,
Iam new into learning pl/sql.Iam trying to CROSS JOIN 3 tables and
select some rows based on ROWNUM , but Iam not sure how that data is
getting selected.

I have three tables like the following :
SQL> SELECT * FROM tab1;

C1 C2 C3
---------- ---------- ----------
1 one 123
2 two 234
3 three 345
4 four 456
5 five 567

5 rows selected.

SQL> SELECT * FROM tab2;

C1 C2 C4
---------- ---------- ----------
7 seven 789
2 two 344
3 three 654
4 four 543
5 five 253
6 six 756

6 rows selected.

SQL> SELECT * FROM tab3;

C1 C2 C5
---------- ---------- ----------
8 eight 789
3 two 244
3 three 654
4 four 543
5 five 353
9 nine 756

6 rows selected.

Now I run the following queries ,
SELECT * FROM tab1 CROSS JOIN tab2 CROSS JOIN tab3 WHERE ROWNUM < 3 ;

C1 C2 C3 C1 C2 C4 C1 C2
C5
---------- ---------- ---------- ---------- ---------- ----------
----------
1 one 123 7 seven 789 8 eight
789
1 one 123 7 seven 789 3 two
244

SELECT * FROM tab1 CROSS JOIN tab2 CROSS JOIN tab3 WHERE ROWNUM = 1 or
ROWNUM = 2;
C1 C2 C3 C1 C2 C4 C1 C2 C5
------- ---------- ---------- ---------- ---------- ----------
1 one 123 7 seven 789 8 eight 789
2 two 234 7 seven 789 8 eight 789

SELECT * FROM tab1 CROSS JOIN tab2 CROSS JOIN tab3 WHERE ROWNUM <= 2;

C1 C2 C3 C1 C2 C4 C1 C2
C5
---------- ---------- ---------- ---------- ---------- ----------
----------
1 one 123 7 seven 789 8 eight
789
1 one 123 7 seven 789 3 two
244

Iam bit confused with all the above outputs as the WHERE clause for
all the above statements looks similar, but the output is not as per
my expectation.

Can anyone help me understand on what basis are we getting the above
outputs.

TIA

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.