在尝试outer join
查询时,我注意到将一个条件从子句更改where
为join
子句会更改结果。这让我感到惊讶,但我将表格和查询简化如下,现在我想我明白了,但我想听听一个可靠的解释。
create table t0 (id int, b int);
create table t1 (id int, b int);
insert into t0 (id, b) values (1, 10), (2, 10);
insert into t1 (id, b) values (1, 2);
select t0.id, t0.b
from t0
left outer join t1 on
t0.id = t1.id
where
t0.b = 10
and
t1.b = 2
;
id | b
----+----
1 | 10
(1 row)
现在我将条件之一从子句where
移到join
子句:
select t0.id, t0.b
from t0
left outer join t1 on
t0.id = t1.id
and
t1.b = 2
where
t0.b = 10
;
id | b
----+----
1 | 10
2 | 10
(2 rows)
你知道如何写一个直截了当的推理吗?