select concat(a.username, '@', d.domain) source, a.destination from virtualalias a inner join virtualdomain d on d.enabled = 1 and d.id = a.domain where coalesce(a.destination, '') <> '' and a.action not in ('reject', 'discard') and not exists ( select 1 from virtualuser u where u.enabled = 1 and u.alias = a.id ) union all select concat(r.mailbox, '@', dr.domain), r.destination from rfc2142 r cross join virtualdomain dr where dr.enabled = 1 and not exists ( select 1 from virtualalias ar where coalesce(ar.destination, '') <> '' and ar.action not in ('reject', 'discard') and ar.domain = dr.id and ar.username = r.mailbox )