所以我试图将两个不相关的表中所有可能的ID组合插入到我创建的引用表中。下面是我的表格以及一些示例数据:
Entity_ID Time_Zone_Id
1 1
1 2
2 1
2 2
3 1
3 2
期望的最终结果:
select entity_id, time_zone_id
from (select entity as entity_id
, null as time_zone_id
from entity
UNION ALL
select null as entity_id
, time_zone_id as time_zone_id
from time_zone);
我尝试过(但失败了):
"<div>text<div>"
我如何得到我想要的结果?提前谢谢!
答案 0 :(得分:4)
您可以使用CROSS JOIN
:
SELECT DISTINCT e.entity_id, t.time_zone_id
FROM entity e
CROSS JOIN time_zone t
ORDER BY e.entity_id, t.time_zone_id;
答案 1 :(得分:3)
Select DISTINCT e.entity_id, tz.time_zone_id
from entity e cross join time_zone tz