Is there a way to reference an aliased column so it doesn't throw a column is ambiguous error (without renaming the alias)? Example:
Select coalesce(a.dob, b.birth_date) as dob
From db.table1 a
Join db.table2 b (on a.field1 = b.field1)
Where dob = '1900-01-01' <--- throws an error because it doesn't know if dob is coming from db.table1 or the aliased field that I want to alias dob.
This is my silly work around but wondered if there is a better solution:
Select q.dob2 as dob
From(
Select coalesce(a.dob, b.birth_date) as dob2
From db.table1 a
Join db.table2 b (on a.field1 = b.field1)
Where dob2 = '1900-01-01'
) q
Forums: