Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ItBurns
Jul 24, 2007
I have three tables that I'm trying to join, really only two that I'm trying to join via an intermediary. The issue is that they use two different IDs for the same person. One table, Table_A, has ID_One. I'm linking this to a second table, Table_B, that has both ID_One and ID_Two, with the goal to then use that to finally link to Table_C. The only issue is that this is a one to many join when going from Table_A to Table_B, with Table_B having multiple rows of ID_One for every instance of ID_Two, but I really only care about a single row in Table_B because I'm just trying to get at the second ID in this table, ID_Two. The third table only has ID_Two, and has just one entry for every person.

My current solution looks like this...

code:
select
  ID_One,
  ID_Two
from (
  select
    ID_One,
    ID_Two,
    max( ID_Two ) over ( partition by ID_One ) as max_ID_Two
  from
    Table_B ) max_B
where
  max_B.ID_Two = max_B.max_ID_Two
This gives me an unduplicated table of ID_One and ID_Two that I can use join Table_A and Table_C. Is this the best, or even correct, approach? This is happening in Oracle, if there are better approaches for that system.

ItBurns fucked around with this message at 01:31 on Jun 11, 2015

Adbot
ADBOT LOVES YOU

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply