sql - Join when exact match other other wise join with default value -


i have 2 table , b 

table a

   id          b     c 

table b

   id           value                1       b             2    default       0 

so want join 2 tables on id when matching, otherwise use default value desired results

   id           value                1       b             2    c             0 

use left outer join purpose like

select t1.id, coalesce(t2.value, 0) value tablea t1  left join tableb t2 on t1.id = t2.id; 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -