Search code examples
sqlms-access

SQL Error in Video Rental Database (JOIN ON THREE TABLES)


I have the following Relationship diagram taken from Microsoft Access:

enter image description here

AND I want to run the following SQL Query:

SELECT c.CATEGORY_CODE, c.CATEGORY_DESCRIPTION
FROM CATEGORIES c
INNER JOIN MEDIA m ON m.CATEGORY_CODE = c.CATEGORY_CODE
INNER RENTALS r ON r.MEDIA_TITLE = m.MEDIA_TITLE
WHERE r.RENTAL_DATE > DATE();

AND I get the following error:

enter image description here

Any ideas as to why MS Access is giving me this error ? I think it has to do with the second join. Thanks.


Solution

  • It's a simple syntax error, you were missing JOIN for INNER JOIN on the RENTALS table and you'll need to use parenthesis when doing multiple joins

    Here is your SQL with the corrections

    SELECT c.CATEGORY_CODE, c.CATEGORY_DESCRIPTION
    FROM (CATEGORIES c
    INNER JOIN MEDIA m ON m.CATEGORY_CODE = c.CATEGORY_CODE)
    INNER JOIN RENTALS r ON r.MEDIA_TITLE = m.MEDIA_TITLE
    WHERE r.RENTAL_DATE > DATE();