• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Single table two column dependency query

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

please guide
 
Did you miss me? Did you miss this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic