-1

I have an Oracle view (joined from multiple tables) like the first screen shot. the address_type should be always either owner or property. I want to get results like the second screen shot. How to use SQL to do that? Sorry I am a very beginner to SQL.

enter image description here

enter image description here

sstan
  • 35,425
  • 6
  • 48
  • 66
Alex W.
  • 546
  • 1
  • 7
  • 22

1 Answers1

1

You can use an inner join:

select tab1.address_id, tab1.address as owner_address,
       tab1.city as owner_city, tab1.state as owner_state, 
       tab1.zip as owner_zip, tab2.address as property_address,
       tab2.city as property_city, tab2.state as property_state, 
       tab2.zip as property_zip  
from tab1
full outer join tab2
on tab1.address_id = tab2.address_id 
where tab1.address_type = 'owner'
      and tab2.address_type = 'property'

tab1 contains all owner informations, tab2 contains all property informations. You can join them using address_id.

Sorry i can't test it!

Francesco Serra
  • 763
  • 8
  • 13