Reputation: 125344
I need to join two tables. If b column is empty then the join will be done on c column. If not the join will be on b column.
This works as I need. But I suspect I'm missing something as it looks a bit convoluted for what it does:
select *
from the_table t
inner join another_table a
on
case when a.b = '' then
case when t.c = a.c then 1 else 0 end
else
case when t.b = a.b then 1 else 0 end
end = 1
Am I missing something?
Upvotes: 1
Views: 246