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
email | email
user@gmail.com | NULL
NULL | organization@gmail.com
email
user@gmail.com
organization@gmail.com
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
)