File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and the fly likes what query will solve this? (picture diagram included) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "what query will solve this? (picture diagram included)" Watch "what query will solve this? (picture diagram included)" New topic

what query will solve this? (picture diagram included)

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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
internet detective

Joined: May 26, 2003
Posts: 30138

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
jQuery in Action, 2nd edition
subject: what query will solve this? (picture diagram included)
Similar Threads
Hibernate:Eager fetching
Improving An Algorithm
Bind a whole class in jsp?
how to extract parents and childs from a table with self reference?
multicolumn TreeViewer with composite as content