aspose file tools*
The moose likes JDBC and the fly likes Single table two column dependency query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Single table two column dependency query" Watch "Single table two column dependency query" New topic
Author

Single table two column dependency query

Nikes Shah
Ranch Hand

Joined: Jul 18, 2007
Posts: 133
Hi friends,

My question is not related to JDBC but SQL.

I have dependency table as follows.

Now I want to get all unique values from ColumnA and ColumnB for dependencies.

Let us say user wants dependency for A1.

here

so now I have to find dependency for B1.

(I already have dependency for A1 so exclude from this result).

Now I have to find dependency for A2,A3,A4 (unique)...

unique values from above output ----- A2,A3,A4,B1,B2 (B1 is already included in second step of output)...
so again till now unique dependencies are.....
A1(search term),A2,A3,A4,B1,B2

remaining from above is B2, so for B2 now dependency is as below...
A2,A4,A5,A6 (I have to exclude A2,A4 as it has already been part of the search )

so for A5,A6

so final dependencies are A1,A2,A3,A4,b1,B2,B3.

How can I implement this logic in any SQL.

I have some experience in SQL Server stored procedure.
I think cursor, temporary table features can be used in this scenario as.

If you guys have any other solution/suggestion then please guide. I do not want ready made code but some initial steps so I can do it myself.

Thanks for any help.
Vinoth Thirunavukarasu
Ranch Hand

Joined: Dec 18, 2008
Posts: 164

Use "DISTINCT" key word


Java Best Practices
Linux Best Practices
Amortization Calculator

Nikes Shah
Ranch Hand

Joined: Jul 18, 2007
Posts: 133
Use "DISTINCT" key word


I can use "DISTINCT" key word when I have final values that may contain duplicates.

My question is how to process dependency logic.... here I can have 1000+ dependencies.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
And the JOIN clause.
Nikes Shah
Ranch Hand

Joined: Jul 18, 2007
Posts: 133
I started using cursors, but not able to go ahead.

please guide
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Single table two column dependency query