Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Inner Joins and Hierarchical Queries

Re: Inner Joins and Hierarchical Queries

From: Nigel Thomas <nigel_cl_thomas_at_yahoo.com>
Date: Thu, 14 Dec 2006 11:39:44 -0800 (PST)
Message-ID: <20061214193944.76295.qmail@web58704.mail.re1.yahoo.com>


Ian

SELECT EMPNO, ENAME, LEVEL, V
FROM EMP, (SELECT 'A' AS V FROM DUAL
           UNION SELECT 'B' FROM DUAL)
CONNECT BY PRIOR EMPNO = MGR
START WITH EMPNO = 7839
Order by LEVEL, ENAME
/

Yes, it's expected, you're effectively doing a hierarchical query on the cartesian join of 2 rows from dual with EMP

Logically equivalent to:

insert into emp select * from emp;

do the original hierarchical query on EMP

rollback;

(Try it - but you may have to lose any PKs and UKs on EMP)

What you thought you were getting would be:

SELECT *
FROM (
   SELECT EMPNO, ENAME, LEVEL FROM EMP
   CONNECT BY PRIOR EMPNO = MGR
   START WITH EMPNO = 7839
   ),
  (SELECT 'A' AS V FROM DUAL
           UNION SELECT 'B' FROM DUAL)
ORDER BY LEVEL, ENAME ie a cartesian join of the result of the hierarchical query. Cartesian join and hierarchical query are not associative!

Regards Nigel

--
http://www.freelists.org/webpage/oracle-l
Received on Thu Dec 14 2006 - 13:39:44 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US