Lets say I have a two table both with a SSN variable, and I want to show the ones that are in only one table, not both.
What is the correct way to do this?
Here is one way:
select coalesce(t1.ssn, t2.ssn)
from t1 full outer join
t2
on t1.ssn = t2.ssn
where t1.ssn is null or t2.ssn is null;
This works in most databases, but not in MySQL. The following should work in pretty much any database:
select ssn
from ((select ssn, 't1' as which
from t1
) union all
(select ssn, 't2' as which
from t2
)
) t
group by ssn
having count(distinct which) = 1