Postgresql left join 时,为不存在的记录增加默认值

Postgresql left join 时,为不存在的记录增加默认值

1
2
3
4
5
6
7
8
9
select
t1.key,
t1.name,
case
when exists(select 1 from t2 where t2.key = t1.key)
then t2.info
else 'n/a'
END
from t1 left join t2 on t1.key = t2.key;