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!

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

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.

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

Perfect! Thanks very much!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.