code_junkie

How to select a related group of items in Oracle SQL

Nov 12th, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. Key ID Link
  2. 1 MASTER 123
  3. 2 AA 123
  4. 3 AA 123
  5. 4 BB 123
  6. 5 MASTER 456
  7. 6 CC 456
  8.  
  9. 1 MASTER 123
  10. 2 AA 123
  11. 3 AA 123
  12.  
  13. SELECT DISTINCT key, id, link
  14. FROM the_table
  15. START WITH id = 'AA'
  16. CONNECT BY id = 'MASTER' and link = PRIOR link and 'AA' = PRIOR ID
  17.  
  18. select i.link from table i
  19. where i.id = YOUR_ID
  20.  
  21. select * from table
  22. where link in (select i.link from table i where i.id = YOUR_ID)
Add Comment
Please, Sign In to add comment