I am doing an outer join of two tables by 2 columns. A join should occur if table1.column1 = table2.column1 and table1.column2 = table2.column2. Since column2 is allowed to contain null, the union fails when the value is null, since null is not null (only a computer scientist can love it).
The workaround I came across is:
select table1.column1,table1.colunn1,table2.column1,table2.column2 from table1 left join table2 on table1.column1=table2.column1 and if(table1.column2 is null,table2.column2 is null, table1.column2=table2.column2)
This works correctly, but should there be a better way?
source share