A family of Microsoft relational database management systems designed for ease of use.
Here it is. Many thanks.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Morning, I have got a problem with Queries on my computer running Windows 11.
I explain: I would like that, every time, when I want to add products on my list to be bought, the query shows me if this or these products are seaseonable.
I tried many times but unsuccessfully! Please see attached relations between tables.
I don't know SQL at all.
Many thanks for your help.
Regards,
CM
A family of Microsoft relational database management systems designed for ease of use.
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
The primary key of Products is ID, not ProductID, so you could change the query to:
SELECT Products.*
FROM Products INNER JOIN MonthAvailable ON Products.ID = MonthAvailable.ProductID
WHERE MonthAvailable = MONTH(DATE()) OR MonthAvailable IS NULL;
Though, rather than the above, I would recommend against the generic ID as a column name, and rename the ID column in Products ProductID. The query as it stands will then work as expected. Do the same with the Recipes table.
Thank you. I did what you recommended, but it returns ONLY seasonal products, not NULL ones.
Do you want to see?
Mea culpa! I missed the crucial requirement, which is that the JOIN must be a LEFT OUTER JOIN:
SELECT Products.*
FROM Products LEFT JOIN MonthAvailable ON Products.ID = MonthAvailable.ProductID
WHERE MonthAvailable = MONTH(DATE()) OR MonthAvailable IS NULL;
Normally you cannot restrict a query using a LEFT OUTER JOIN on a value in a column on the right side of the join. In effect it becomes an INNER JOIN. However, this is an exception to that. By testing the column for NULL or a value it will, by virtue of the NULL, return all rows from the table on the right of the join with no match, and, by testing for an actual value in a Boolean OR operation, also those rows with a match on the specified value.
Thanks Kevin, but it doesn't work either! On RequestSQL1, only Seasonal Products pop up; on RequestSQL2, all my data appear. What I would like, as explained, is only the products of a specific month (i.e January until midnight) and the possibility to add other data that don't require a specific month.