Solved

Nested query

Posted on 2006-11-01
3
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

627 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