So I have a few tables in my database. Let's say I have
CREATE TABLE ARTICLE (
id INT NOT NULL IDENTITY PRIMARY KEY,
time_stamp BIGINT(20) NOT NULL UNIQUE,
body TEXT NOT NULL,
title VARCHAR(255),
web_address VARCHAR(255) NOT NULL UNIQUE
);
and
CREATE TABLE BLOG (
id INT NOT NULL IDENTITY PRIMARY KEY,
time_stamp BIGINT(20) NOT NULL UNIQUE,
body TEXT NOT NULL,
title VARCHAR(255) NOT NULL UNIQUE
);
and
CREATE TABLE LINKTABLE (
id INT NOT NULL IDENTITY PRIMARY KEY,
parent_id INT,
quote_id INT,
article_id INT,
blog_id INT,
FOREIGN KEY (parent_id) REFERENCES Blog(id)
ON DELETE CASCADE,
FOREIGN KEY (blog_id) REFERENCES Blog(id)
ON DELETE CASCADE,
FOREIGN KEY (article_id) REFERENCES Article(id)
ON DELETE CASCADE,
FOREIGN KEY (quote_id) REFERENCES Quote(id)
ON DELETE CASCADE
);
Now, if I have the following command:
SELECT b.id as blog_id, l.blog_id as linktable_blog_id, l.id as linktable_id
FROM linktable l
LEFT JOIN blog b ON
(l.blog_id=b.id OR l.parent_id=b.id)
where there exists an entry in linktable and blog that satisfies the constraints I get returned the following as I would expect:
{"blog_id":1,"linktable_blog_id":1,"linktable_id":1}
HOWEVER supposing I have
SELECT a.id as article_id, b.id as blog_id, l.blog_id as linktable_blog_id, l.id as linktable_id
FROM linktable l
LEFT JOIN blog b ON
(l.blog_id=b.id OR l.parent_id=b.id)
LEFT JOIN article a ON
l.article_id=a.id
Where there is neither an article nor an entry in the linktable I get returned
{}//empty
Where what I am trying to do is get
{"blog_id":1,"linktable_blog_id":1,"linktable_id":1, "article_id": null}
Any suggestions?