有人能告诉我为什么只有第三个查询有效吗?我会理解是否NULL
会empty column/string
得到不同的待遇,但为什么第二个查询不起作用?转换is_disabled
和is_terminated
转换VARCHAR(3)
也无济于事。
谢谢
桌子:
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`fullname` varbinary(100) NOT NULL,
`is_disabled` enum('Yes') DEFAULT NULL,
`is_terminated` enum('Yes') DEFAULT NULL
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
数据:
id - fullname - is_disabled - is_terminated
1 - User One - {this is just empty column} - NULL
问题 1:
SELECT id, fullname FROM users
WHERE id = '1'
AND
is_disabled != 'Yes' /* is_disabled <> 'Yes' */
AND
is_terminated != 'Yes' /* is_terminated <> 'Yes' */
问题 2:
SELECT id, fullname FROM users
WHERE id = '1'
AND
is_disabled = '' /* is_disabled IS NULL */
AND
is_terminated = '' /* is_terminated IS NULL */
问题 3:
SELECT id, fullname FROM users
WHERE id = '1'
AND
(is_disabled = '' OR is_disabled IS NULL)
AND
(is_terminated = '' OR is_terminated IS NULL)