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
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: 33102

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]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: SQL question
It's not a secret anymore!