开发者

select rows with column that is not null?

开发者 https://www.devze.com 2022-12-24 02:37 出处:网络
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.

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

精彩评论

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