[英]Cartesian join two tables with no records
I have to join Table A (tax related) to Table B (customer related) 我必须将表A(与税相关)加入表B(与客户相关)
I pull at most 1 record but sometimes no record. 我最多只能取得1条记录,但有时却没有记录。
Now I need to return the combined record to the user 现在我需要将合并的记录返回给用户
I though doing a simple Cartesian product would have work 我虽然做一个简单的笛卡尔积就可以
SELECT * FROM TableA, TableB
but that does not work if TableA or TableB is empty 但是如果TableA或TableB为空则不起作用
I would do a full outer join but right now do not have anything to join on. 我会做一个完整的外部连接,但是现在没有任何连接。 I could create temp tables with identity columns and then join on them (since 1 = 1)
我可以创建带有标识列的临时表,然后加入它们(因为1 = 1)
But I was looking for a different way? 但是我在寻找不同的方式吗?
Thank you 谢谢
Per your own suggestion, you could use a full outer join
to guarantee a row: 根据您自己的建议,可以使用
full outer join
来保证一行:
select *
TableA a
full outer join
TableB b
on 1=1
To always return at least one row, even if TableA
and TableB
are emtpy, you could use a fake table: 要始终返回至少一行,即使
TableA
和TableB
为空,也可以使用伪造的表:
select *
from (
select 1 as col1
) fake
left join
TableA a
on 1=1
left join
TableB b
on 1=1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.