There are two tables T1(col1) and T2(col1, col2) which needs to be joined. But T2 may have col1 as null in which case col2 can be used as backup.
What I want is either join on T1.col1 = T2.col1
or T1.col1 = T2.col2
if col1 is NULL in T2.
I have already tried these:
select * from T2 left join T1
on T1.col1 = coalesce(T2.col1, T2.col2)
select * from T2 left join T1
on T1.col1 in (T2.col1, T2.col2)
select * from T2 left join T1
on T1.col1 = T2.col1
or T1.col1 = T2.col2)
Which result in the ETL job never ending.
Additional info:
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
SELECT
*
FROM
T2
LEFT JOIN
T1
ON T1.col1 = coalesce(T2.col1,
T2.col2)