IN CLAUSE OUTPUT [message #618206] |
Wed, 09 July 2014 06:50 |
|
anniepeteroracle
Messages: 47 Registered: March 2012 Location: bangalore
|
Member |
|
|
SQL> ed
Wrote file afiedt.buf
1* select * from dept where deptno in (30,10,20)
SQL> /
DEPTNO DNAME LOC
---------- -------------- -------------
20 RESEARCH DALLAS
10 ACCOUNTING NEW YORK
30 SALES CHICAGO
SQL> ed
Wrote file afiedt.buf
1* select * from dept where deptno in (10,30,20)
SQL> /
DEPTNO DNAME LOC
---------- -------------- -------------
20 RESEARCH DALLAS
30 SALES CHICAGO
10 ACCOUNTING NEW YORK
SQL> ed
Wrote file afiedt.buf
1* select * from dept where deptno in (30,20,10)
SQL> /
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
------------------------------------------------------------------------------
HERE THE OUTPUT IS DIFFERENT AS PER IN CLAUSE
IS IT WORKING LIKE LAST IN FAST OUT (LIFO)
|
|
|
Re: IN CLAUSE OUTPUT [message #618209 is a reply to message #618206] |
Wed, 09 July 2014 07:05 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
Without an ORDER BY you cannot depend on the order of rows returned.
SQL> select * from dept where deptno in (30,10,20) ORDER BY deptno;
DEPTNO DNAME LOC
------ -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
SQL> select * from dept where deptno in (10,30,20) ORDER BY deptno;
DEPTNO DNAME LOC
------ -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
SQL> select * from dept where deptno IN (30,20,10) ORDER BY deptno;
DEPTNO DNAME LOC
------ -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
|
|
|
|
Re: IN CLAUSE OUTPUT [message #618215 is a reply to message #618206] |
Wed, 09 July 2014 08:08 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
anniepeteroracle wrote on Wed, 09 July 2014 17:20
IS IT WORKING LIKE LAST IN FAST OUT (LIFO)
In addition to what I and Michel said above, see the rows returned by the same query WITHOUT an order by is different for me than yours, however, in all 3 cases I don't get what you said LIFO.
SQL> select * from dept where deptno in (30,10,20)
2 /
DEPTNO DNAME LOC
------ -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
SQL> select * from dept where deptno in (10,30,20)
2 /
DEPTNO DNAME LOC
------ -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
SQL> select * from dept where deptno in (30,20,10)
2 /
DEPTNO DNAME LOC
------ -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
Hence you cannot guarantee the order in which rows are returned, unless you specify ORDER BY.
|
|
|
|
|
|