sql - 如何在 SQL 中使用交叉连接创建左连接?
问题描述
如何在不实际使用 SQL 中的左连接的情况下创建等效于左连接的查询?
解决方案
你不能轻易做到这一点cross join
。您可以inner join
使用and来做到这一点union all
:
select a.*, b.*
from a join
b
on . . .
union all
select a.*, . . . -- manually put in b columns
from a
where not exists (select 1 from b where . . . ); -- join conditions in the `where` clause
推荐阅读
- java - 如何使用 ! 解码 %21 swagger 编辑器中 URL 的查询参数中的符号
- sql - Teradata:将重复值转换为逗号分隔字符串的结果
- powershell - Powershell 返回错误的输出
- sql - Postgres 查询左连接耗时太长
- c++ - 无法使用 Visual Studio 2019 访问虚幻引擎 4.25 中的头文件
- python - 使用邮箱访问 mbox 中的所有字段
- android - 如何在管理控制台中将设备状态设置为禁用时在设备中显示自定义消息?
- r - 通过节点/顶点查找图中的所有路径
- mongodb - MongoDB 聚合 - 按 _id 分组,然后按另一个字段优先级
- java - 在 Java Swing 的菜单栏上显示图标