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

Melanie Hobbel
Melanie Hobbel
841 Points

What am I doing wrong?

So I'm doing something wrong and I don't understand what. The task is:

''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" ''

I enter below:

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

And then I get this:

''Bummer! Expecting two rows, please check that you are checking for both names and they are correct.''

I just don't see it. Can someone please tell me what my mistake is?

Thanks!

3 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Try using the "LIKE" keyword with your WHERE clause.

SELECT * FROM users WHERE last_name LIKE "Hinkley" OR "Pettit";
Melanie Hobbel
Melanie Hobbel
841 Points

Doesn't work either:

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

'' Bummer! You're missing an equal to operator (=)''

Steven Parker
Steven Parker
231,248 Points

:x: You cannot extend a "LIKE" comparison using only "OR".

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Alright, I think I've found the answer. We don't need like as that searches for patterns in strings. So forget that.

Instead use AND as your operator so both results are retrieved.

SELECT * FROM users WHERE last_name LIKE "Hinkley" AND "Pettit"; 

It will search for those last names and include them, but ignore the other records.

Melanie Hobbel
Melanie Hobbel
841 Points

Thanks for your help - unfortunately it's also not working..

" Bummer! You're missing an OR keyword! "

Seems like nothing is wrong but it keeps disapproving the answer..

Steven Parker
Steven Parker
231,248 Points

:x: You cannot extend a "LIKE" comparison using only "AND". Also, AND is not the correct logic for the requirement.

Steven Parker
Steven Parker
231,248 Points

Melanie Hobbel, in case you haven't resolved this by now...

:point_right: Your final comparison is incomplete.

You need a complete comparison expression after the "OR":

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

Another (and more compact) way to do multiple comparisons is by using the "IN" expression:

SELECT * FROM users WHERE last_name IN ("Hinkley", "Pettit");