Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Single table two column dependency query

 
Nikes Shah
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use "DISTINCT" key word
 
Nikes Shah
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the JOIN clause.
 
Nikes Shah
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I started using cursors, but not able to go ahead.

please guide
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic