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 trialMelanie Hobbel
841 PointsWhat 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
Treehouse Moderator 91,253 PointsTry using the "LIKE" keyword with your WHERE clause.
SELECT * FROM users WHERE last_name LIKE "Hinkley" OR "Pettit";
Jonathan Grieve
Treehouse Moderator 91,253 PointsAlright, 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
841 PointsThanks 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
231,248 Points You cannot extend a "LIKE
" comparison using only "AND
". Also, AND is not the correct logic for the requirement.
Steven Parker
231,248 PointsMelanie Hobbel, in case you haven't resolved this by now...
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");
Melanie Hobbel
841 PointsMelanie Hobbel
841 PointsDoesn't work either:
'' Bummer! You're missing an equal to operator (=)''
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsThat's interesting....
Steven Parker
231,248 PointsSteven Parker
231,248 PointsYou cannot extend a "LIKE" comparison using only "OR".