Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Databases

Using 2 Inner Joins at the same time?

How do I use 2 joins at once? I'm getting a syntax error (Missing Operator).

SELECT Rentals.RentalDate, Rentals.Due, Customers.lastname, Customers.firstname, Media.ItemTitle FROM Rentals INNER JOIN Customers ON Rentals.Customer = Customers.ID INNER JOIN Media ON Rentals.Media = Media.ItemTitle WHERE Date() > Rentals.Due;

Steven Parker
Steven Parker
216,083 Points

Can you provide a link to the challenge? The query syntax looks good, but perhaps there's some specific requirement of the challenge that is not being met.

It's a little project I'm working on in Microsoft Access. It's driving me nuts :-P

Steven Parker
Steven Parker
216,083 Points

In that case, can you show the DDL?

1 Answer

Steven Parker
Steven Parker
216,083 Points

Just a wild guess.

Without seeing the challenge, I'm just wondering if that last join should be:

  ... INNER JOIN Media ON Rentals.Media = Media.ID ...

It would make sense if the Media table were constructed like the Customers table.

I did change it to that. It works with either INNER JOIN but not with Both

It turns out the MS Access requires Brackets with multiple join statements.

Thank you for helping me work through it!

SELECT Rentals.RentalDate, Rentals.Due, Customers.lastname, Customers.firstname, Media.ItemTitle FROM ((Rentals INNER JOIN Customers ON Rentals.Customer = Customers.ID) INNER JOIN Media ON Rentals.Media = Media.ID) WHERE Date() > Rentals.Due;

Steven Parker
Steven Parker
216,083 Points

I knew it did that if you use the query builder, but I didn't think they were actually required for it to run.