rspec/rules/S1639/rule.adoc

21 lines
443 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
While ``++NOT IN++`` can be far more efficient than ``++NOT EXISTS++`` in a query, it may return misleading results if the column in question contains null values.
2020-06-30 12:47:33 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:47:33 +02:00
----
SELECT COUNT(*) FROM emp
WHERE empno NOT IN ( SELECT mgr FROM emp );
----
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:47:33 +02:00
----
SELECT COUNT(*) FROM emp T1
WHERE NOT EXISTS ( SELECT NULL FROM emp T2 WHERE t2.mgr = t1.empno );
----