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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -