我得到了以下查询。 这应该返回一行,但它不会。
不幸的是没有。
当我删除最后一个连接子句时:
LEFT JOIN `serene_pagecontent` ON `serene_pageorder`.`pageorder_id` = `serene_pagecontent`.`pagecontent_link`
我确实得到了一个结果。但是当添加时它并没有。 据我所知,在加入之前添加LEFT应该会提供结果,即使其中一个字段丢失了。
SELECT * FROM `serene_page`
LEFT JOIN `serene_pageoptions` ON `serene_page`.`page_id` = `serene_pageoptions`.`pageoptions_link`
LEFT JOIN `serene_pagetitle` ON `serene_page`.`page_id` = `serene_pagetitle`.`pagetitle_link`
LEFT JOIN `serene_pageorder` ON `serene_page`.`page_id` = `serene_pageorder`.`pageorder_link`
LEFT JOIN `serene_pagecontent` ON `serene_pageorder`.`pageorder_id` = `serene_pagecontent`.`pagecontent_link`
WHERE `page_id` = 34 AND `pageoptions_language` = 'NL' AND `pagetitle_language` = 'NL' AND `pagecontent_language` = 'NL'
任何人都可以告诉我我错过了什么。
修改
WHERE `serene_page`.`page_id` = 34
AND serene_pageoptions`.`pageoptions_language` = 'NL'
AND serene_pagetitle`.`pagetitle_language` = 'NL'
AND serene_pagecontent`.`pagecontent_language` = 'NL'
编辑解决方案:解决方案" juergen d"
SELECT * FROM `serene_page` LEFT JOIN `serene_pageoptions` ON `serene_page`.`page_id` =`serene_pageoptions`.`pageoptions_link` AND `serene_pageoptions`.`pageoptions_language` = 'NL' LEFT JOIN `serene_pagetitle` ON `serene_page`.`page_id` = `serene_pagetitle`.`pagetitle_link` AND `serene_pagetitle`.`pagetitle_language` = 'NL' LEFT JOIN `serene_pageorder` ON `serene_page`.`page_id` = `serene_pageorder`.`pageorder_link` LEFT JOIN `serene_pagecontent` ON `serene_pageorder`.`pageorder_id` = `serene_pagecontent`.`pagecontent_link` AND `serene_pagecontent`.`pagecontent_language` = 'NL' WHERE `serene_page`.`page_id` = 34
我不知道如果没有,我必须添加子条款 它会变成正常的JOINS。谢谢!
答案 0 :(得分:0)
如果你sourceIMG.addEventListener('click', function() {
$.get('https://newsapi.org/v1/articles?source=' + this.id + '&sortBy=latest&apiKey=APIKEYHERE', function(data, status) {
console.log(data);
latestArticles = data.articles;
for (i = 0; i < latestArticles.length; i++) {
//New Article
var newArticle = document.createElement("DIV");
newArticle.id = "article";
newArticle.className += "article";
//Title
//Create an h1 Element
var header = document.createElement("H1");
//Create the text entry for the H1
var title = document.createTextNode(latestArticles[i].title);
//Append the text to the h1 Element
header.appendChild(title);
//Append the h1 element to the Div 'article'
newArticle.appendChild(header);
//Author
var para = document.createElement("P");
var author = document.createTextNode(latestArticles[i].author);
para.appendChild(author);
newArticle.appendChild(para);
//Description
var description = document.createElement("H4");
var desc = document.createTextNode(latestArticles[i].description);
description.appendChild(desc);
newArticle.appendChild(description);
//Image
var image = document.createElement("IMG");
image.src = latestArticles[i].urlToImage;
image.className += "articleImg";
newArticle.appendChild(image);
//Url link
//Create a href element
var a = document.createElement('a');
var link = document.createElement('p');
var innerLink = document.createTextNode('Read the full story ');
link.appendChild(innerLink);
a.setAttribute("href", latestArticles[i].url);
a.innerHTML = "here.";
link.appendChild(a);
newArticle.appendChild(link);
//Append the Div 'article' to the outer div 'articles'
document.getElementById("articles").appendChild(newArticle);
}
});
}, false);
,你需要将连接表的条件放入JOIN中。否则LEFT JOINS变成INNER JOINs
left join