如何重写左联接

时间:2019-06-19 09:27:07

标签: sql impala

请考虑以下查询:

constructor(..., private route: ActivatedRoute){}

对于此特定示例,我可以将LEFT JOIN重写为INNER JOIN +查询,以获取不在“ rt”表中的所有ID:

this.router.navigate(['details', '1029'], {relativeTo: route, skipLocationChange: true});

在此示例中,两个查询器都给出相同的结果。但这通常是真的吗?我可以用这种方式重写任何左联接(或者可能有更短的方法)吗?

1 个答案:

答案 0 :(得分:0)

您可以在下面尝试-

DEMO

select val1, NULL as id2, NULL as val2 from lt where id1 not in (select id2 from 
rt) 
union 
select val1,id1, val1 from lt where 1=1 and id1 in (select id2 from rt)

输出:

val1    id2 val2
one     
two     2   two
three   3   three