Suppose I had the following 2 tables:
Table1: Table2:
Col1: Col2: Col3: Col1: Col2: Col
you can just map like that
select * from tableA a
join tableB b on isnull(a.colID,'') = isnull(b.colId,'')
You can be explicit about the joins:
SELECT Table1.Col1, Table1.Col2, Table1.Col3, Table2.Col4
FROM Table1 INNER JOIN
Table2
ON (Table1.Col1 = Table2.Col1 or Table1.Col1 is NULL and Table2.Col1 is NULL) AND
(Table1.Col2 = Table2.Col2 or Table1.Col2 is NULL and Table2.Col2 is NULL)
In practice, I would be more likely to use coalesce()
in the join condition:
SELECT Table1.Col1, Table1.Col2, Table1.Col3, Table2.Col4
FROM Table1 INNER JOIN
Table2
ON (coalesce(Table1.Col1, '') = coalesce(Table2.Col1, '')) AND
(coalesce(Table1.Col2, '') = coalesce(Table2.Col2, ''))
Where ''
would be a value not in either of the tables.
Just a word of caution. In most databases, using any of these constructs prevents the use of indexes.