Question: I have one main table `t` with people characteristics to which I want to join information on birth dates from two other tables `m` and `n`, thus creating column `birth_date` in table `t`. The key variable I am joining on is `ID` which appears in all three tables.

The problem I have is that table `t` contains variable `age` and I want to join birth dates from table `m` **only if** `t.age < 18` and birth dates from table `n` **only if** `t.age >= 18`. 
What I have now is:

```
select t.*,
       m.birth_date as birth_date_1,
       n.birth_date as birth_date_2
from t
left join m
on (t.ID = m.ID and t.age < 18)
left join n
on (t.ID = n.ID and t.age >= 18);

```

This seems to work, however, I created two columns `birth_date_1` and `birth_date_2`. How can I do this within this one select to create only one column `birth_date`?

Answer: 
> 
> How can I do this within this one select to create only one column birth\_date?
> 
> 
> 

Since at most one of the left joins will succeed for each record in the source table, you can just use `coalesce()`:

```
select t.*, coalesce(m.birth_date, n.birth_date) as birth_date
from t
left join m on t.ID = m.ID and t.age < 18
left join n on t.ID = n.ID and t.age >= 18

```

Side note: parentheses around the join conditions are superfluous.
You can

```
SELECT
    [...],
    COALESCE(m.birth_date, n.birth_date) AS birth_date,
    [...]

```