Boolean returning case
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?
ON (a.b = '' AND t.c = a.c) OR (a.b <> '' AND t.b = a.b)
精彩评论