L
L
Lavrov952018-11-19 03:13:44
SQL
Lavrov95, 2018-11-19 03:13:44

How to margin after join?

after this script,

select o.email, u.email from apartments a
left join users u on u.id = a.publisher_id AND a.publisher_type=0
left join organizations o on o.id=a.publisher_id AND a.publisher_type=1

outputs like this
email                   |    email
[email protected] | NULL
NULL                   | [email protected]

how can i make it output
email 
[email protected]
[email protected]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Telepnev, 2018-11-19
@TelepnevDmitriy

Select coalesce(o.email, u.email)...

S
Stalker_RED, 2018-11-19
@Stalker_RED

Another option:

select email from users where id in(
  select distinct publisher_id from apartments where publisher_type=0
)
UNION 
select email from organizations where id in(
  select distinct publisher_id from apartments where publisher_type=1
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question