Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

what query will solve this? (picture diagram included)

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Below is a diagram describing the relationship between items (Parent-Child).

The items are stored in a database as parentID and ChildID (lower left in the photo)

Q: What query will return the table below (or just the list of ALL child) if I input the MAIN Parent (in the example 7); in other word: SELECT (algorithm) WHERE parentID=7

Thank you!

 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 35976
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
It sounds like you are looking for how to do a recursive query. This isn't possible using generic SQL. You can use a stored procedure or a database specific function (if your database has one.) This article shows the approach for db2 and oracle.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!