左连接表,添加到表达式

Left join tables, add to on expression

我在左连接两个表时遇到问题。请帮我。 我有两张桌子: 所以如果 TableA 是

A B
1 a
2 b
3 c

而表 B 是

A B
1 d
2 e

然后Select * from TableA left join TableB on TableA.A = TableB.Areturns

1 a 1 d
2 b 2 e
3 c null null

但是:Select * from TableA left join TableB on TableA.A = TableB.A where TableB.B = 'e' returns:

2 b 2 e

还有问题,我怎样才能得到这样的东西:

2 b 2 e
3 c null null

非常感谢。

您似乎想要从 TableB 获取所有匹配项,其中 B 字段等于 'e'NULL:

Select * 
from TableA 
left join TableB on TableA.A = TableB.A 
where (TableB.B = 'e') or (TableB.B is null)

给你

Select * from TableA left join TableB on TableA.A = TableB.A 
where TableB.B = 'e' OR TableB.B is NULL

除了与 Table.B='e'

匹配的行之外,您将从表中获得空行