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 SQL Basics Finding the Data You Want Filtering by Dates

Luis Manuel Lopez Hidalgo
seal-mask
.a{fill-rule:evenodd;}techdegree
Luis Manuel Lopez Hidalgo
Full Stack JavaScript Techdegree Student 23,195 Points

Not a question but a comment. I think in the last part of the video what we want is the patron_id and not the id.

I think we need the patron_id because they are the people we are looking to send an email.

1 Answer

Hi Luis,

I think these are the 2 queries you're referring to:

SELECT * FROM loans WHERE return_by > "2015-12-18";

SELECT first_name, email FROM patrons WHERE id = 1 OR id = 3;

It's correct to use id in the second query because Andrew is querying the patrons table which doesn't have a patron_id column but it does have an id column used as the primary key.

The loans table does have a patron_id column. This is used as a foreign key on the patrons table. It creates a relationship between the 2 tables. The patron_id column in the loans table corresponds to the id column in the patrons table.

With the 1st query Andrew looked at the patron_id column from the loans table to discover that patrons 1 and 3 haven't returned their books yet. Andrew then searches for those id's in the patrons table (using the id column) to get their contact information.