Gonna give an example since it’s hard to understand what i’m talking about:
SELECT a.f1,
b.f1,
IF(a.f3 <> '', a.f3, b.f3) as f3
FROM a
LEFT JOIN b
ON b.f4 = a.f4
WHERE f3 = 'something'
Now, this won’t work because i can’t have an alias as a field in the where clause, so how can I apply the condition to that f3 field that’s either from a or b. Preferably without putting a bunch of IFs in the where clause
Try this:
This is actually less efficient than replacing the value with the formula itself as it will require a full scan. To improve performance (but decrease readability) you can use this query: