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'
。
誰會向我解釋這種行爲。
在此先感謝。