Dale Fye
asked on
Comparing data in three tables
Looking to compare data from three different data sources, I have far more columns to include in the comparison, but for simplicity
Lets just say I have:
This obviously involves at least one Full Outer Join
SELECT Coalesce(A.ID, B.ID) as ID, A.SomeValue as Value_A, B.SomeValue as Value_B
FROM SELECT ID, SomeValue FROM Table_A as A
FULL OUTER JOIN
SELECT ID, SomeValue from Table_B as B
ON A.ID = B.ID
But I'm confused on how to accomplish this for Table_C. Do I have to wrap the above as a subquery or CTE and then join that to Table_C, or can I simply add another line for Table_C (and if the latter) do I join on A.ID = C.ID or B.ID = C.ID or some other join condition?
Or would some sort of union query as a subquery and a Pivot query work better
Lets just say I have:
Table_A Table_B Table_C
ID Somevalue ID Somevalue ID Somevalue
1 3 1 3 2 5
2 4 3 5 3 6
I would like the query results as:ID Value_A Value_B Value_C
1 3 3 NULL
2 4 NULL 5
3 NULL 5 6
This obviously involves at least one Full Outer Join
SELECT Coalesce(A.ID, B.ID) as ID, A.SomeValue as Value_A, B.SomeValue as Value_B
FROM SELECT ID, SomeValue FROM Table_A as A
FULL OUTER JOIN
SELECT ID, SomeValue from Table_B as B
ON A.ID = B.ID
But I'm confused on how to accomplish this for Table_C. Do I have to wrap the above as a subquery or CTE and then join that to Table_C, or can I simply add another line for Table_C (and if the latter) do I join on A.ID = C.ID or B.ID = C.ID or some other join condition?
Or would some sort of union query as a subquery and a Pivot query work better
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked perfectly.
ASKER