After question update:
As @Craig already informed you, a WHERE
condition on B
would only select matching rows in B
and act like a [INNER] JOIN
instead of a LEFT [OUTER] JOIN
.
You need to pull that WHERE
condition up into the condition of the LEFT JOIN
.
While being at it, I opportunistically simplified with USING
, since all joining column names are identical. Details in the manual.
Information is still incomplete and contradicting. Here is another educated guess:
SELECT a.factor, a.categorical_value
, COALESCE(a.positive, b.positive) AS positive
, COALESCE(a.negative, b.negative) AS negative
FROM features a
LEFT JOIN profiles b USING (factor, categorical_value, uuid)
WHERE a.uuid='9e5083da74305628336631da9d2903e3'
Not sure if you need to join on udid
, too.
Your example would indicate COALESCE(b.positive, a.positive)
. Something does not add up ...
More updates in comment
Adapt your JOIN condition then:
SELECT a.factor, a.categorical_value
, COALESCE(a.positive, b.positive) AS positive
, COALESCE(a.negative, b.negative) AS negative
FROM features a
LEFT JOIN profiles b ON a.factor = b.factor
AND a.categorical_value = b.categorical_value
AND b.uuid='9e5083da74305628336631da9d2903e3';