0

Hi,

I was wondering what is the "cleanest" way of combining two datasets by taking all the values from one data set and only the values from a second data set that have an index that does not appear in the first.

Both data sets have the same columns.

Even if there is an entry in the second data set with the same index as the first but different values, it should not be included.

Thanks in advance for any help!

2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by js8765
0

you may use left, right outer joins to control result as expected.

select t1.col1,t1.col2, t2.col1, t2.col2 
from db1.table1 t1 
left outer join db2.table2 t2 
on t1.CommonColName=t2.CommanColName
0

Hi urtrived,

Thanks for you quick answer. Your solution is not exactly what I was looking for.

Here's an example for what I was hoping to do:

t1

id value
-- -----
1 valueA
2 valueB
3 valueC
4 valueD

t2

id value
-- -----
2 valueE
3 valueF
4 valueG
5 valueH

Desired result
id value
-- -----
1 valueA
2 valueB
3 valueC
4 valueD
5 valueH

Thanks again for any help.

1

I hope following query will help you

SELECT case when t1.id is null then t2.id else t1.id end id
, case when t1.id is null then t2.value else t1.value end value
FROM db1.table1 t1 FULL OUTER JOIN db2.table2 t2 ON t1.ID=t2.ID
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.