左外连接和额外的 where 子句 [英] Left Outer join and an additional where clause
本文介绍了左外连接和额外的 where 子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对定义为左外连接的两个表进行了连接,以便所有记录都从左侧表返回,即使它们在右侧表中没有记录.但是,我还需要在右侧表中的字段上包含一个 where 子句,但是......我仍然希望为左侧表中的每条记录返回左侧表中的一行,即使不满足 where 子句中的条件.有没有办法做到这一点?
I have a join on two tables defined as a left outer join so that all records are returned from the left hand table even if they don't have a record in the right hand table. However I also need to include a where clause on a field from the right-hand table, but.... I still want a row from the left-hand table to be returned for each record in the left-hand table even if the condition in the where clause isn't met. Is there a way of doing this?
推荐答案
是的,把条件(称为谓词)放在连接条件中
Yes, put the condition (called a predicate) in the join conditions
Select [stuff]
From TableA a
Left Join TableB b
On b.Pk = a.Pk
-- [Put your condition here, like this]
And b.Column = somevalue
这篇关于左外连接和额外的 where 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文