File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes SQL question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL question" Watch "SQL question" New topic

SQL question

Joe Joseph

Joined: Jun 21, 2006
Posts: 20

Suppose i have 4 tables t1, t2, t3, t4.
The below query will fetch me a resultset i am interested in:
Select * from t1, t2, t3, t4 where = and = and = and = and = and = ( i have simplified the conditions in this example here for simplicity sake).
My problem is that i am also interested in finding the orphan records in each table ( ie records with entries missing on the tables for a trade). Note that i cannot use the outer joins here as this might yield me multiple records. How could i proceed with this ?
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32087

You would need to do this as two queries (or a union of two queries.) The first is the one to find the non-orphaned data, which you have. The second is an outer join with a distinct filter for the orphaned data.

[OCA 8 book] [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
I agree. Here's the link:
subject: SQL question