rspec/rules/S1639/rule.adoc

23 lines
471 B
Plaintext

== Why is this an issue?
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 );
----