Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

How to query for patrons with no loans?

In a library database, there are three tables for books, loans (with dates for loans) and patrons. It is easy to query for the patron info for patrons who already have outstanding loans. But how do we select for patrons who don't have any loans and hence, whose id won't be in the loans table? You have to use JOIN clauses.

2 Answers

Steven Parker
Steven Parker
231,128 Points

If you use a "LEFT OUTER JOIN", the patrons will still be included but any field from the loans table will be null. So you can select just those rows "WHERE loans.patron_id IS NULL".

For more specific answers, always show your query code and include a link to the course page you are working with.

Thanks