I have a table where I record the purchases made by the site.
I use a field called status_plataforma
to receive the transaction status of the SecurePage. This field, besides being able to receive an integer, by default it is NULL
.
In a given query, I needed to know if the status_plataforma
field is not with the value 6
or 7
. For this, I'm using the WHERE status_plataforma NOT IN(6, 7)
condition.
However, when this field is set to NULL
, the result is not found!
That is, I do not have 6
nor 7
in this column, but only NULL
and, theoretically, the result should be returned.
My Tests:
Example without NOT IN
:
mysql> select id, preco, status_plataforma, concluida FROM compras WHERE site_cadastro_aluno_id = 43;
+----+-------+-------------------+-----------+
| id | preco | status_plataforma | concluida |
+----+-------+-------------------+-----------+
| 41 | 29.90 | NULL | 0 |
+----+-------+-------------------+-----------+
1 row in set (0,00 sec)
The problem happens when I use NOT IN
:
mysql> select id, preco, status_plataforma, concluida FROM compras WHERE site_cadastro_aluno_id = 43 AND status_plataforma NOT IN (6,7);
Empty set (0,00 sec)
As you can see in the previous query, in fact status_plataforma
is neither 6
nor 7
, but NULL
.
Why did NOT IN
have this behavior?