Reputation: 7647
I thought NOT IN
behaves the same as !=
in a query. But a query using !=
returns more rows than a query using NOT IN
:
SELECT count(A.NO)
FROM A
WHERE
A.CODE != 'a'
AND
A.CODE != 'b'
AND
A.CODE != 'c'
AND
A.NAME != 'd'
AND
A.NAME != 'e'
returns 1566 rows, whereas
SELECT count(A.NO)
FROM A
WHERE
A.CODE NOT IN ('a','b','c')
AND
A.NAME NOT IN ('d','e')
returns only 1200 rows.
I suppose NOT IN
excludes NULL
values - would that be the only difference?
Upvotes: 6
Views: 156
Reputation: 109613
No answer but what delivers the following?
SELECT *
FROM A
WHERE
A.CODE != 'a'
AND
A.CODE != 'b'
AND
A.CODE != 'c'
AND
A.NAME != 'd'
AND
A.NAME != 'e'
AND NOT (
A.CODE NOT IN ('a','b','c')
AND
A.NAME NOT IN ('d','e')
)
LIMIT 0, 20
Upvotes: 0