mysql - 我有一个主表和一个来自 sql 查询的结果。如何加入这些主表和一个结果集以获取丢失的 ID
问题描述
表 1:“材料”
id
1
2
3
4
5
询问:
SELECT ID FROM
(Select * From
(Select Distinct(ID) from tablex Union All
Select Distinct(ID) from tabley Union All
Select Distinct(ID) from tablez Union All )
来自上述查询的 o/p 是 1,2 &3
结局输出要求:4 5
解决方案
如果您想要主表中的 id 而不是子表中的 id,您可以使用not exists
:
select m.*
from master m
where not exists (select 1 from child1 c1 where c1.id = m.id) and
not exists (select 1 from child2 c2 where c2.id = m.id);
推荐阅读
- html - django web应用程序中周期性页面刷新对服务器的影响
- reactjs - 如何在 react-select 中定义选项的最大限制?
- c# - EF Core ASP.Net Core 编辑迁移
- openssl - 有什么办法可以避免 pro*c 预编译器?
- android - 如何使用 exoplayer 播放字节数组?
- java - 垃圾收集器不会自行释放内存
- python - 尝试模拟修补函数,但获取 PIL\\Image.py'> 没有属性“保存”
- postgresql - 我无法通过 pqxx::sql_error::sqlstate() 获取 sqlcode
- php - 在 wordpress 中调用随机无模板部分
- node.js - nexus repo npm install ERRORCONNRESET