I have a query that is joining two tables. I would like to be able to create an alias that allows the value to default to a different field when the original field is null. Here is an example:
select
Table1.Name,
Table2.Name,
(case when Table1.Name then Table2.Name else Table1.Name end) AS 'RealName'
from Table3
left join Table1 on Table1.ID = Table3.Table1_ID
left join Table2 on Table2.ID = Table3.Table2_ID
order by `RealName` asc
I am getting an "unknown column in field list" error when I try doing this.
Update: Turns out my unknown column error was due to something else. The MySQL coalesce function worked great for this.