I have a simple query that I can't seem to get it to work correctly. I have a table that has just one field call "CODE". This is query between 3 databases, so I need to be able to order them in sequence and have it ouput side by side. All 3 databases has same table and 1 field call "CODE".
DB1 DB2 DB3
AAB1 AAB1 AAB1
BB32 NULL BB32
CDB4 NULL NULL
NULL NULL DDEF3
JJL12 JJL12 NULL
I tried the following, but can't seem to sort correctly.
SELECT D1.CODE AS DB1, D2.CODE AS DB2, D3.CODE AS DB3
FROM DB1.DBO.PRODUCT D1 FULL OUTER JOIN DB2.DBO.PRODUCT D2
ON D1.CODE = D2.CODE FULL OUTER JOIN DB3.DBO.PRODUCT D3
ON D2.CODE = D3.CODE OR D1.CODE = D3.CODE