So I know the title might seem confusing. To begin with, I created a table called Items that contained ItemNo as a primary key, along with Title and Description. I then created a table called Articles with ArticleNo as a primary key, along with Author and Text.
I then realised I wanted to link these two tables, so added another key to the Articles table (called ItemNo) and linked it to the Items table.
The query I’m using is:
SELECT Articles.ArticleTitle, Articles.Author, Articles.Text, Images.ImagePath, Articles.ArticleNo
FROM Articles, Images
INNER JOIN RelatedImagesArticles
WHERE Articles.ArticleNo = RelatedImagesArticles.ArticleNo
AND Images.ImageNo = RelatedImagesArticles.ImageNo AND Articles.ItemNo = ?
(The other tables and fields mentioned are working fully)
Now that I’ve added the ItemNo constraint, the above query only works on fields added before the constraint was added and completely ignores fields added after. I’m using PHPMyAdmin if that helps.
I know my issue doesn’t contain much information, not sure how else to add more relevant info in a clear way. If any more info is needed I’ll try and provide
2
Answers
Figured it out. The query would only ever return articles that have a corresponding image. If an article doesn't have an image, then the article field is completely ignored
Do not use commas in the
FROM
clause. Rephrase the query using properJOIN
syntax:I think you are trying to describe a scoping issue, but your language is hard to follow. You query doesn’t have a “constraint” in the SQL sense.
Constraint
s are things in tables. It does have conditions, specificallyJOIN
conditions between tables and filtering conditionswithin a table.