rspec/rules/S1639/rule.adoc
2022-02-04 16:28:24 +00:00

21 lines
443 B
Plaintext

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.
== Noncompliant Code Example
[source,text]
----
SELECT COUNT(*) FROM emp
WHERE empno NOT IN ( SELECT mgr FROM emp );
----
== Compliant Solution
[source,text]
----
SELECT COUNT(*) FROM emp T1
WHERE NOT EXISTS ( SELECT NULL FROM emp T2 WHERE t2.mgr = t1.empno );
----