dbTalk Databases Forums  

Can this be done?

comp.databases.oracle.server comp.databases.oracle.server


Discuss Can this be done? in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sheldonlg
 
Posts: n/a

Default Can this be done? - 08-07-2011 , 03:55 PM






I have two tables
A: field1, field2
B: field1, field2

field2 always has a value in table A.
table B may or may not have a record with a value of field1 matching
that of table A.

I want to get the value of field2. I want the value for the record with
the value of field1 to come from Table B if there is a record there for
that value of field1, otherwise I want the value to come from table A.

If that is confusing, here is an example:

Table A
field1 field2
101 39
102 75
103 94
104 66

Table B
field1 field2
102 81
104 67

I want the results to be for the query for records where field1 IN
(101,102) obtained to be

field1 field2
101 39
102 81

Any hints?

--
Shelly

Reply With Quote
  #2  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: Can this be done? - 08-07-2011 , 05:32 PM






On 07.08.2011 22:55, sheldonlg wrote:
Quote:
I have two tables
A: field1, field2
B: field1, field2

field2 always has a value in table A.
table B may or may not have a record with a value of field1 matching
that of table A.

I want to get the value of field2. I want the value for the record with
the value of field1 to come from Table B if there is a record there for
that value of field1, otherwise I want the value to come from table A.

If that is confusing, here is an example:

Table A
field1 field2
101 39
102 75
103 94
104 66

Table B
field1 field2
102 81
104 67

I want the results to be for the query for records where field1 IN
(101,102) obtained to be

field1 field2
101 39
102 81

Any hints?

select A.field1,nvl(B.field2,A.field2)
from tableA A,tableB B
where A.field1=B.field1(+)
and A.field1 in (101,102)

Best regards

Maxim

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.