LEFT JOIN无法按预期工作??? [英] LEFT JOIN does not Work as Expected???

查看:96
本文介绍了LEFT JOIN无法按预期工作???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们!


这是另一个非常奇怪的人,我想知道是否有人对我的 LEFT JOIN的原因有任何见解无效。以下是查询:

Hey Folks!

Here''s another extremely weird one, and I''m wondering if anyone has any insight as to why my LEFT JOIN is not working. Here is the Query:

展开 | 选择 | Wrap | 行号

推荐答案

嗨Twinny。


OUTER JOIN 的常见混淆


LEFT JOIN中的每条记录数据集但不是 INNER JOIN 数据集被 WHERE 子句排除。所有这些记录对于来自联接的右侧的任何字段都具有NULL值,但是如果它们是True或False,则只允许它们通过。显然,没有人可以,因为他们总是空的。


NB。我已经将标题更改为更准确。
Hi Twinny.

A very common confusion with OUTER JOINs

Every record that is in the LEFT JOIN dataset but not the INNER JOIN dataset is excluded by your WHERE clause. All of those records have NULL values for any of the Fields from the RIGHT side of the join, but you only let them through if they''re True or False. Obviously, none can ever be either as they''re always NULL.

NB. I''ve changed the title to be more accurate.


要解决此问题,您需要将过滤条件移动到连接条件中,或者使用条件将连接的右侧子查询,或者将(字段为空或字段=值)添加到右侧的每个条件。


我通常只使用第一个选项。
To resolve, you need to move the filtering criteria into the join condition, or subquery the right side of the join with the criteria, or add (field is null or field = value) to each criteria that is on the right side.

I typically just use the first option.


我花了一些高飞的头脑来理解这一点,但如果我 正确理解,在不改变查询结构的情况下,下面的WHERE子句应该产生我想要的结果吗? (我不在检查这个)

It took me a few Goofy head-scratches to understand this, but if I do understand correctly, without changing the structure of the query, the following WHERE clause should produce my desired results? (I am not at work to check this)

展开 | 选择 | Wrap | 行号


这篇关于LEFT JOIN无法按预期工作???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆