我有以下2个表t1,t2的值,
t1        t2
1         4
2         2
3         3
现在我要输出
1 
4
如何在选择查询中获得此输出?
这将为您提供t1不存在的t2每个项目,并且其中的每个项目t2都不存在于t1:
select t1.id from t1
left join t2 on t2.id = t1.id
where t2.id is null
union all
select t2.id from t2
left join t1 on t1.id = t2.id
where t1.id is null
(我假设每个表中的字段名称id只是为了能够针对表编写查询而命名.)
另一种方式是:
select coalesce(t1.id, t2.id)
from t1
full outer join t2 on t2.id = t1.id
where t1.id is null or t2.id is null