【发布时间】:2017-04-13 19:07:02
【问题描述】:
有结构:
CREATE TABLE `contents` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(45) NULL,
PRIMARY KEY (`id`));
CREATE TABLE `content_values` (
`content_id` INT UNSIGNED NOT NULL,
`field_id` INT UNSIGNED NOT NULL,
`value` VARCHAR(45) NULL,
PRIMARY KEY (`content_id`, `field_id`));
INSERT INTO `contents` VALUES (1,'test-title-1'),(2,'test-title-2');
INSERT INTO `content_values` VALUES (1,4,'test-value');
http://sqlfiddle.com/#!9/028d0/5
还有两个查询:
1
select contents.*, content_values.value
from contents
left join content_values on content_values.content_id=contents.id and
content_values.field_id = 4;
2
select contents.*, content_values.value
from contents
left join content_values on content_values.content_id=contents.id and
content_values.field_id = 4
where content_values.value != '123';
我想知道为什么作为第二个查询的结果,没有行,其中有 NULL 对应 content_value.value。毕竟条件是!= '123'。
谁会向我解释这种行为。
提前致谢。
【问题讨论】:
标签: mysql null left-join where-clause