在下面的查询中,我想将外部连接留在table3上。不应该导致ID大于table1中的表ID的所有行。为什么我的SQL查询不能正常工作?
这对我来说应该返回table3中所有大于table1 ID的行。那么情况并非如此。
问题:这是否应该返回所有具有 大于table1 ID的ID的行?
注:我知道,从条款 在周围切换表的顺序会改变所产生的数据集。
select t1.ID, t1.Value,
t3.ID, t3.Value
from table1 as t1
left outer join
table3 as t3 on t1.ID > t3.ID;
结果:
1 First NULL NULL
2 Second 1 First
表1:
ID Value
1 First
2 Second
表3:
ID Value
1 First
2 Second
3 Third
4 Fourth
5 Fifth
6 Sixth
7 Seventh
8 Eighth
此查询返回结果表,我认为它应该用于此类查询。但第一个例子并不像我认为的那样工作。因为这会匹配所有正确的tabel,其ID小于当前的t1.ID,这是它应该如何工作的。 (看上面)
select t1.ID, t1.Value,
t3.ID, t3.Value
from table1 as t1
left outer join
table3 as t3 on t1.ID < t3.ID;
结果:
1 First 2 Second
1 First 3 Third
1 First 4 Fourth
1 First 5 Fifth
1 First 6 Sixth
1 First 7 Seventh
1 First 8 Eighth
2 Second 3 Third
2 Second 4 Fourth
2 Second 5 Fifth
2 Second 6 Sixth
2 Second 7 Seventh
2 Second 8 Eighth
所以**你认为第一个结果集有什么错误? – podiluska
'x> y'表示'x'大于'y'。再看看你在''''的两边有什么。 –