【发布时间】:2021-05-20 08:42:23
【问题描述】:
我有两张表需要加入。第二个表用于过滤第一个表中的记录。
- table1.参数
- table2.参数; table2.parameter_group
结果应包括 table1 中某个 parameter_group 的所有记录,还应包括参数为 null 的记录。
我所拥有的是:
table1 LEFT JOIN table2
ON table1.parameter=table2.parameter
WHERE table2.parameter_group IS 'A' OR table1.parameter IS NULL
我的问题是 - 这是实现目标的最有效方式吗?关键是每个过滤器(parameter_group IS 'A' OR table1.parameter IS NULL)只针对非常大的 table1 中的百分之几的记录。 我认为这是关于澄清(向我解释)处理顺序...谢谢您的帮助。
【问题讨论】:
-
您的查询和 Gordon 的答案返回不同的答案集。您的查询(在修复了无效的
IS 'A'语法之后)会导致内部联接,而 Gordon 会返回所有行。