>>>Hi everybody,
>>>
>>>I am struggling to create one SQL select that will create a query as following (simplified):
>>>
>>>
>>>1. table mytable1 has the following records:
>>>
>>>PK_VAL
>>>1
>>>2
>>>3
>>>
>>>2. table mytable2 has the following records:
>>>PK_VAL
>>>1
>>>2
>>>5
>>>6
>>>
>>>
>>>I want to create a query of all records in mytable1 plus records in mytable2 that have PKs missing in mytable1. In the example above, the resulting query would have the following records:
>>>
>>>PK_VAL
>>>1 (from mytable1)
>>>2 (from mytable1)
>>>3 (from mytable1)
>>>5 (from mytable2)
>>>6 (from mytable2).
>>>
>>>
>>>Thank you in advance for any help.
>>
>>select nvl(MyTble1.PK,myTble2.PK) as PK from myTable1
>>right join myTable2 on myTable1.PK = myTable2.PK
>
>Thank you. I will give it a try.
Or you can switch table 2 and 1 and use a left join. E.g. select
nvl(myTable1.PK, myTable2.PK) as PK from myTable2 left join myTable1 ...
You can also always use FULL OUTER JOIN.
If it's not broken, fix it until it is.
My Blog