I have the following query which is supposed to be selecting all the articles from Articles_New which are either A) not in ArticlesInCategories_New or B) in it, but do not have the CategoryID = 7, 8, 9, 10, or 11.
By removing the Category != lines, I’ve determined that the problem is (at the least) that Articles_New is not selecting everything from Articles_New that is not in ArticlesInCategories_New. I still don’t really understand GroupBy, but I’ve based off of other questions, I’ve tried GroupBy Articles_New.ArticleID, and that didn’t change anything.
SELECT
DISTINCT Articles_New.ArticleID,
DATE_FORMAT(Articles_New.PublicationDate, '%c/%e/%Y') AS ReleaseDate,
Articles_New.Title,
Articles_New.Type,
Articles_New.URL
FROM
Articles_New
LEFT JOIN ArticlesInCategories_New
ON ArticlesInCategories_New.ArticleID = Articles_New.ArticleID
WHERE
PublicationDate >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH) AND
PublicationDate <= CURDATE() AND
Articles_New.Public = '1'
AND ArticlesInCategories_New.CategoryID != '7'
AND ArticlesInCategories_New.CategoryID != '8'
AND ArticlesInCategories_New.CategoryID != '9'
AND ArticlesInCategories_New.CategoryID != '10'
AND ArticlesInCategories_New.CategoryID != '11'
ORDER BY
Articles_New.PublicationDate DESC,
Articles_New.ArticleID DESC
You want all rows that are either:
A) not in ArticlesInCategories_New
B) in ArticlesInCategories_New, but do not have CategoryID = 7, 8, 9, 10, or 11.