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
Solved

showing a sub hierachy in a main hierarchy query using connect by prior

Posted on 2007-03-25
1
416 Views
Last Modified: 2013-12-19
folks

here is a hierarchy in oracle

SELECT LPAD(' ',2*(LEVEL-1)) || TO_CHAR(location) s
  FROM location
  START WITH location ='12000'
  CONNECT BY PRIOR location = parent;

AS  you see the table is called location,my asset table also has its own hierarchy,but in affect has a relation to the location table location.location =asset.location,below is its own hierarchy
 
  SELECT LPAD(' ',2*(LEVEL-1)) || TO_CHAR(ASSETNUM) s
  FROM asset
  START WITH assetnum ='AGV314'
  CONNECT BY PRIOR assetnum = parent;

 how do i join both selects?to show all locations as all its assets in one hierarchical query?

all help will do
0
Comment
Question by:rutgermons
1 Comment
 
LVL 15

Accepted Solution

by:
OMC2000 earned 500 total points
ID: 18791100
SELECT location, a.s,  b.s FROM
(SELECT location, LPAD(' ',2*(LEVEL-1)) || TO_CHAR(location) s
  FROM location
  START WITH location ='12000'
  CONNECT BY PRIOR location = parent) a
LEFT OUTER JOIN
(SELECT location,  LPAD(' ',2*(LEVEL-1)) || TO_CHAR(ASSETNUM) s
  FROM asset
  START WITH assetnum ='AGV314'
  CONNECT BY PRIOR assetnum = parent) b
ON a.location = b.location

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

839 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