Access Queries

Anonymous
2025-01-27T08:46:50+00:00

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

Microsoft 365 and Office | Access | For home | Windows

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.

0 comments No comments

45 answers

Sort by: Oldest
  1. Anonymous
    2025-01-30T15:12:58+00:00

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2025-01-30T17:02:06+00:00

    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.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2025-01-31T07:44:12+00:00

    Thank you. I did what you recommended, but it returns ONLY seasonal products, not NULL ones.

    Do you want to see?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2025-01-31T12:51:48+00:00

    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.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2025-01-31T13:45:49+00:00

    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.

    https://www.dropbox.com/scl/fi/x0oezar8iswaedsau80e4/Recipes-SQL.accdb?rlkey=g9n2s8kk3r31xdo3a9wbmlqdj&st=0mlksa9t&dl=0

    Was this answer helpful?

    0 comments No comments