mysql检查值为null

Ron*_*tel 0 mysql sql null

在mysql表中real_account_id的数据类型是int(11).我想获取具有NULL值的所有记录.

我正在使用这个简单的查询.

SELECT * FROM `customer_payment_options` WHERE real_account_id = NULL
Run Code Online (Sandbox Code Playgroud)

但是,它没有给我任何结果.数据库中有2条记录具有NULL值.我也尝试过,

SELECT * FROM `customer_payment_options` WHERE real_account_id = 'NULL'
Run Code Online (Sandbox Code Playgroud)

为什么会这样?谢谢.

Joh*_*nde 7

NULL等于什么,包括NULL.这就是你必须使用的原因IS NULL:

SELECT * FROM `customer_payment_options` WHERE real_account_id IS NULL
Run Code Online (Sandbox Code Playgroud)