I'm trying to SELECT some result related between 2 tables by codes.
**Table_1**
+---------+-------------------------------------+
| code | description |
|---------|-------------------------------------|
| 00001 | Code 00001 |
| 00002 | Code 00002 |
| 00003 | Code 00003 |
| 00004 | Code 00004 |
+---------+-------------------------------------+
**Table_2**
+---------+---------------+
| id | code_ref |
|---------|---------------|
| 1 | 00001 |
| 2 | 00002 |
| 3 | |
| 4 | NULL |
+---------+---------------+
I use this query to select the code from Table 1 which doesn't exist in Table 2:
SELECT *
FROM Table_1
WHERE code NOT IN (
SELECT DISTINCT code_ref
FROM Table_2
)
With this query it returned empty result. Then i tried to add WHERE code_ref <> '' into the subquery, it can return result properly. I this the problem or some rule about the empty string and null value is different?