EXISTS
в улье должно быть коррелировано .Вот так
select * from a
where EXISTS (select 1 from x where x.col=a.col) --correlated condition
То же, что вы можете достичь с помощью объединений (предположим, ключ объединения не дублирует):
--checking NOT EXISTS
select * from a
left join X on x.col=a.col --same condition like in correlated EXISTS query
where x.col is null --not exists
--checking EXISTS can be done using INNER JOIN:
select * from a
inner join x on x.col=a.col --same condition like in correlated EXISTS query
--checking EXISTS can be done using LEFT SEMI JOIN:
select * from a
left semi join x on x.col=a.col
--Insert into table X only if partition is empty (JOIN):
insert overwrite table X partition(p)
select col1, col2, p--partition col
from Y
left join (select distinct p from X) x1 on y.p=x1.p
where x1.p is null
--Insert into table X only if partition is empty (EXISTS):
insert overwrite table X partition(p)
select col1, col2, p--partition col
from Y
WHERE NOT EXISTS (select 1 from X x1 where x1.p=Y.p)