Поскольку вы можете иметь БАННЕРЫ без ЭЛЕКТРОННОЙ ПОЧТЫ, а также ЭЛЕКТРОННЫЕ ПОЧТЫ без БАННЕРОВ, вам потребуется пользователь FULL OUTER JOIN.
SELECT
nvl(A.DATE, b.date) as DATE,
nvl(A.USER_ID, b.user_id) as USER_ID,
c.client as banner_client_id,
A.BANNER_ID,
A.IMPRESSIONS,
B.EMAIL_ID,
D.CLIENT AS EMAIL_CLIENT_ID
FROM
BANNERS A
FULL OUTER JOIN EMAILS B ON (A.USER_ID=B.USER_ID AND
a.DATE = b.DATE and
A.CLIENT_ID = B.CLIENT_ID)
LEFT OUTER JOIN CLIENTS C ON (C.CLIENT_ID= a.CLIENT_ID)
LEFT OUTER JOIN CLIENTS D ON (D.CLIENT_ID= B.CLIENT_ID)
Полная версия запроса, включая некоторые примеры данных, показана ниже:
with banners as (
select date '2011-04-05' as date_col, 'AX745' as user_id, 'CC' as client_id, 'CC45' as banner_id, 4 as impressions from dual union all
select date '2011-04-05' as date_col, 'AX745' as user_id, 'KC' as client_id, 'KC56' as banner_id, 1 as impressions from dual union all
select date '2011-04-07' as date_col, 'XY555' as user_id, 'DP' as client_id, 'CC45' as banner_id, 2 as impressions from dual
),
emails as (
select date '2011-04-05' as date_col, 'AX745' as user_id, 'EM001' as email_id, 'CC' as client_id from dual union all
select date '2011-04-05' as date_col, 'AX745' as user_id, 'EM005' as email_id, 'BK' as client_id from dual union all
select date '2011-04-07' as date_col, 'XY555' as user_id, 'EM008' as email_id, 'DP' as client_id from dual
),
clients as (
select 'CC' as client_id, 'Coca-Cola' as client_name from dual union all
select 'KC' as client_id, 'KFC' as client_name from dual union all
select 'DP' as client_id, 'Dominos' as client_name from dual union all
select 'BK' as client_id, 'Burger King' as client_name from dual
)
select
nvl(A.DATE_col, b.date_col) as DATE_col,
nvl(A.USER_ID, b.user_id) as USER_ID,
c.client_name as banner_client_id,
A.BANNER_ID,
A.IMPRESSIONS,
B.EMAIL_ID,
D.CLIENT_name AS EMAIL_CLIENT_ID
from
banners a
full outer join emails b on (A.USER_ID=B.USER_ID AND
a.DATE_col = b.DATE_col and
A.CLIENT_ID = B.CLIENT_ID)
left outer join clients c on (a.client_id = c.client_id)
left outer join clients d on (b.client_id = d.client_id)