I'm trying to get the unique values from two tables who both just have one column called domain.
DDL:
create table domains_1 (domain varchar);
create table domains_2 (domain varchar);
DML:
insert into domains_1 values ('example_1.com'), ('example_2.com');
insert into domains_2 values ('example_2.com'), ('example_3.com');
There are a few ways to do this and I decide to use full outer join.
select case when a.domain is null then b.domain
when b.domain is null then a.domain
end as unique_domains
from domains_1 as a full outer join domains_2 as b on a.domain = b.domain;
To my surprise, there is null
in the result besides the unique domains.
I can add one more layer of select
to exclude the null as this:
select * from
(select case when a.domain is null then b.domain
when b.domain is null then a.domain
end as unique_domains
from domains_1 as a full outer join domains_2 as b on a.domain = b.domain) t
where unique_domains is not null;
How can this null
be present in the result in the first place?
Is there any better way to remove the null
from the result?