首页 > 解决方案 > 如何在 SQL 中使用交叉连接创建左连接?

问题描述

如何在不实际使用 SQL 中的左连接的情况下创建等效于左连接的查询?

标签: sqljoinleft-joincross-join

解决方案


你不能轻易做到这一点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

推荐阅读