sql - 如何获得我的结果为 1 2 3 6 7 8 的列我想从两个表中排除公共 ID 并将结果显示在一个列中
问题描述
假设我有两个表 T1 和 T2 以 ID 作为列。例如
T1:ID
1
2
3
4
5
T2:ID
4
5
6
7
8
如何获得我的结果为 1 2 3 6 7 8 的列我想从两个表中排除公共 ID 并将结果显示在一个列中。
解决方案
嗯。. . 一种方法是union all
:
select t1.id
from table1 t1
where not exists (select 1 from table2 t2 where t2.id = t1.id)
union all
select t1.id
from table2 t2
where not exists (select 1 from table1 t1 where t2.id = t1.id);
推荐阅读
- angular - 从使用 Angular 7 的请求中接收 Spring Boot 中的空授权标头,但 Postman 工作正常
- c# - System.Data.SqlClient.SqlException:'')' 附近的语法不正确。' 是那个sql查询错误还是什么?
- spring - 如何将 spring kafka 容器分配给特定的分区并能够停止/启动它?
- java - 将 long 列表转换为 double 列表
- firebase - 在firestore上设置数据时如何获取自动生成的ID?
- jenkins - Jenkins archiveArtifcats 在目录中附加最新文件
- apache-spark - 如何在火花中获取最近三年的数据
- asp.net - 将excel vb宏转换为可执行文件
- vhdl - Verilog 模块或 VHDL 实体中的最大端口数
- node.js - web3.eth.accounts[i] 替代方案?