SQL Where not equal does not return NULL results
As per your where
clause it compares null != 'Iron'
, which evaluates to UNKNOWN which neither true nor false based on SQL's 3 way logic. Hence it is not returned by the query.
If you need the null
row to be resulted, you should use
where content !='Iron' or content is null
Edit: One more option is to use the relational null-safe equality operator <=>
with a negation.
not content <=> 'Iron'
From the documentation,
NULL-safe equal. This operator performs an equality comparison like the = operator, but returns 1 rather than NULL if both operands are NULL, and 0 rather than NULL if one operand is NULL.
The <=> operator is equivalent to the standard SQL IS NOT DISTINCT FROM operator.
mysql>
SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL
UNION
SELECT 1 = 1, NULL = NULL, 1 = NULL;
Returns
1 vs 1 | NULL vs NULL | 1 vs NULL | Comment
--------------------------------------------------
1 | 1 | 0 | for <=>
1 | NULL | NULL | for =
ISNULL(content, '') = 'Iron'
This will convert the null to an empty string.