Reputation: 93146
by default I have one column in MySQL table to be NULL.
I want to select some rows but only if the field value in that column is not NULL.
what is the correct way of typing it?
$query = "SELECT *
FROM names
WHERE id = 1
AND name != NULL";
Is this correct?
Upvotes: 3
Views: 15699
Reputation: 17771
You should use:
$query = "SELECT *
FROM names
WHERE id = 1
AND name IS NOT NULL";
You must use IS NULL
or IS NOT NULL
when working with NULL values
Upvotes: 8
Reputation: 50970
AND name IS NOT NULL
(NULL comparisons require the special IS and IS NOT operator in SQL)
Upvotes: 8