I need help with a raw SQL query which gets a value based on another value.
I have the following raw SQL query.
SELECT pmPropDef.id, pmPropDef.name, pmPropDef.units, pmPropShort.str, pmPropLong.str
FROM pmProp INNER JOIN pmPropDef ON pmProp.propid=pmPropDef.id AND pmPropDef.name = 'Area'
LEFT JOIN pmPropShort ON sid=pmProp.value
LEFT JOIN pmPropLong ON lid=-pmProp.value
WHERE pmProp.ownertype='variant' AND pmPropDef.id = pmProp.propid;
And this results in the following:
+----+------+-------+------+------+
| id | name | units | str | str |
+----+------+-------+------+------+
| 14 | Area | mm2 | 1.1 | NULL |
+----+------+-------+------+------+
The problem that I am getting both pmPropShort.str and pmPropLong.str and I should be betting one or the the other. What I really want is a single str value? How do I re-write this query to meet my needs?
You can use
COALESCEwhich returns the first non-NULL argument. eg.