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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![sowmya Badida](https://secure.gravatar.com/avatar/0b2ae4f4d177f6c778b5699d95334748?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
sowmya Badida
394 PointsHow does SQL know which id to take as we have book_id,patron_id,id in loans table?
select first_name,email from patrons where id =4;
In this query, how does SQL know that it has to select the patron_id only?
4 Answers
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsThe "id" columns all have different names. The column name referenced must match the column name exactly.
The query you listed does not reference "patron_id". It will only look for rows where the column named "id" is equal to 4.
![Talha Takleh Omar Takleh](https://secure.gravatar.com/avatar/a01b4719be0143a7f489cf5537f10771?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Talha Takleh Omar Takleh
3,082 PointsRemember at the beginning of this course where the instructor mentioned that database consists of data and schema. Schema is the organisation of data where the data is stored and divided up into different sections. Sections are also known as tables and these tables can relate to one another.
For this example we have a number of tables. Loans, patrons and books. Since we want to find the patron and the relationship between the tables for loans and patrons is the id. If you look at the patrons table, it has column named id. That's why on the query we can just use id but must refer to the patrons table.
![Julio Mayorga](https://secure.gravatar.com/avatar/2131972fe0d455b381f9f737dc44de9c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Julio Mayorga
1,865 PointsThe above is correct, however, I think he should have looked for id = "5" and not 4. If you look at the table that was pulled it says that the id is 5 and not 4.
![Tineyi Chinhengo](https://secure.gravatar.com/avatar/b7f157f960f2a397d855cd61d98d16c6?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Tineyi Chinhengo
30,770 PointsIf you want to select for patrons_id only. SELECT first_name,email FROM patrons WHERE patrons_id ="4";
If you want to select for id only. SELECT first_name,email FROM patrons WHERE id ="4";
Right now you can see the difference between the 2 and you can choose your correct answer.