Solved

Nested query

Posted on 2006-11-01
3
250 Views
Last Modified: 2008-03-10
I need the result of the two queries combined to give me one output with one list

   SELECT distinct substr(parent,3) division
         FROM wwglph2.wwgl_dv_tree
   CONNECT BY prior child = parent
   START WITH parent  = 'D-SAC'
     ORDER BY 1

returns:
AFD
E0X
INV
MIS
MXO
OSX
RSS
SAC
SCH
SER
SGA
SHD
STC
STD
STH
STX
SZH
USC
VER
XIO
ZBD


   SELECT distinct substr(parent,3) division
         FROM wwglph2.wwgl_dv_tree
   CONNECT BY prior child = parent
   START WITH parent  = 'D-INS'
     ORDER BY 1

retruns :
INS
0
Comment
Question by:rapace3
3 Comments
 
LVL 18

Expert Comment

by:rbrooker
ID: 17854631
Hi,

try :
SELECT *
FROM (SELECT DISTINCT substr(PARENT, 3) division
      FROM wwglph2.wwgl_dv_tree
      CONNECT BY PRIOR child = PARENT
      START WITH PARENT = 'D-SAC'
      UNION ALL
      SELECT DISTINCT substr(PARENT, 3) division
      FROM wwglph2.wwgl_dv_tree
      CONNECT BY PRIOR child = PARENT
      START WITH PARENT = 'D-INS')
ORDER BY 1

or
( not sure if this one will work )

SELECT DISTINCT substr(PARENT, 3) division
FROM wwglph2.wwgl_dv_tree
CONNECT BY PRIOR child = PARENT
START WITH PARENT IN ('D-SAC', 'D-INS')
ORDER BY 1

:)
0
 
LVL 42

Expert Comment

by:dqmq
ID: 17854985
SELECT substr(parent,3) division
         FROM wwglph2.wwgl_dv_tree
   CONNECT BY prior child = parent
   START WITH parent  = 'D-SAC'
UNION
 SELECT substr(parent,3) division
         FROM wwglph2.wwgl_dv_tree
   CONNECT BY prior child = parent
   START WITH parent  = 'D-INS'
     ORDER BY 1

0
 

Accepted Solution

by:
misbah_ra earned 125 total points
ID: 17856798

Select division from
(
SELECT distinct substr(parent,3) division
         FROM wwglph2.wwgl_dv_tree
   CONNECT BY prior child = parent
   START WITH parent  = 'D-SAC'
)
union all
Select division from
(
SELECT distinct substr(parent,3) division
         FROM wwglph2.wwgl_dv_tree
   CONNECT BY prior child = parent
   START WITH parent  = 'D-INS'
)
ORDER BY 1
--You can also use union instead of union all depending on ur requirement
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now