SELECT i.id, i.name, i.whatever,
COALESCE(i.specific1, d.default1) as val1,
COALESCE(i.specific2, d.default2) as val2
FROM tblInstance i
LEFT OUTER JOIN tblDefault d
ON i.foreignKey = d.primaryKey;
COALESCE selects the first non-null value of its arguments, and the left outer join makes sure all records from the left table are returned.
Oh, and whitespace matters in this case. Placing a space between COALESCE and ( produces a general syntax error.
0 Comments