开发者

select rows with column that is not null?

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜