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
而且也有两个疑问:
select contents.*, content_values.value
from contents
left join content_values on content_values.content_id=contents.id and
content_values.field_id = 4;
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'
。
谁会向我解释这种行为。
在此先感谢。