0

I want list all SOURCE_ID if the source has destination, the query below not work probably !!

select SOURCE_ID,
        LINK_TYPE,
        DESTINATION_ID 
from LINK_TABLE
where link_table.link_type=1 
and link_table.destination_is_deleted=0
START WITH link_table.source_id='100'
CONNECT BY PRIOR link_table.source_id=link_table.destination_id

Sample data

SOURCE_ID |  DESTINATION_ID | LINK_TYPE| DESTINATION_IS_DELETED|
----------|-----------------|----------|-----------------------|
100       |      1500       |    1     |             0         |
100       |       1200      |    1     |             0         |
100       |      1300       |    1     |             1         |
1500      |       600       |    1     |             0         |
1500      |       700       |    1     |             0         |
700       |        88       |    1     |             0         |
1
  • Sorry Sir, and thank you for help me. Commented Mar 6, 2017 at 12:01

2 Answers 2

1

Assuming you want to walk the hierarchy from the root nodes to the leaves this is what you need:

select SOURCE_ID,
        LINK_TYPE,
        DESTINATION_ID 
from LINK_TABLE
where link_table.link_type=1 
and link_table.destination_is_deleted=0
START WITH link_table.source_id='100'
CONNECT BY PRIOR link_table.destination_id = link_table.source_id
/

It's just a matter of swapping the referenced columns in the CONNECT BY PRIOR clause. Unfortunately the Oracle syntax is not intuitive here: I've been using it for over twenty years and I still have to test a query to make sure I've got them the right way round :)

Sign up to request clarification or add additional context in comments.

Comments

0

I changed the query structure to solve the issue.

select SOURCE_ID,DESTINATION_ID,link_table.source_class,link_table.linktype,link_table.destination_class
from LINK_TABLE
where (link_table.source_id in( select link_table.DESTINATION_ID from link_table where link_table.source_id='100'and link_table.linktype=1 and link_table.destination_isdeleted=0 ))
and (link_table.linktype=1) or (link_table.source_id='100')  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.