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 DATABASES

SQL DATA

Now we're in the e-commerce database. In the users table we have the columns id, username, password, first_name and last_name. Find all users with either the last name "Hinkley" or "Pettit"

MY CODE:

SELECT * FROM users WHERE last_name = "Hinkley" or "Pettit";

error.: Did you select from the users table and test the last_name column?

4 Answers

Sergey Podgornyy
Sergey Podgornyy
20,660 Points
SELECT * FROM users WHERE last_name = "Hinkley" or last_name ="Pettit";
chase singhofen
chase singhofen
3,811 Points

Its too bad that we have to put last_name is twice. seems kinda redundant, you would think that would be sufficient enough. just like how we put commas after one another ex. last_name, first_name, id, score, etc...

You kinda got it Ary — it's like this:

SELECT * FROM users WHERE last_name = "Hinkley" OR last_name = "Pettit"

Why wouldn't it be acceptable to do:

SELECT * FROM users WHERE last_name = "Hinkley" OR "Pettit";

I mean I get that this throws up an error, but I don't understand why....is it just that SQL can't understand the association of these 2?

I would think it would work that way as well, but I suppose one must be more explicit.

SELECT * FROM users WHERE last_name = "Hinkley" or last_name ="Pettit";