Es ist Struktur:MySQL LEFT JOIN und WHERE-Klausel
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
Und auch gibt es zwei Abfragen:
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';
Ich frage mich, warum, als Ergebnis der zweiten Abfrage gibt es keine Zeile, in der NULL
für content_value.value
ist. Immerhin lautet die Bedingung != '123'
.
Wer würde mir dieses Verhalten erklären.
Vielen Dank im Voraus.