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 = '$id'
AND name != NULL";
is this correct?
You should use (assuming $id
is an integer):
$query = "SELECT *
FROM names
WHERE id = '" . (int) $id ."'
AND name IS NOT NULL";
You must use IS NULL
or IS NOT NULL
when working with NULL values
AND name IS NOT NULL
(NULL comparisons require the special IS and IS NOT operator in SQL)
精彩评论