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 trialSean Loke
14,659 PointsSTAGE 3: PRACTICE MOVIES BEGINNING WITH ALIEN AND WILL OF ACTORS
Q1. Find all movies where the title begins with Alien
SELECT * FROM movies WHERE title LIKE "%Alien%";
produces 2 results. Is this correct?
Q2. Find all actors whos first name starts with Will
SELECT * FROM actors WHERE name LIKE "Will%";
I can't seem to get data which specifically has Will in it. What do I have to add to my code?
Thanks!
2 Answers
Steven Parker
231,271 PointsCan you post a link to the page?
Without seeing the database, I'm just guessing that perhaps the column name you want might be first_name instead of just name?
In the first query, for something that "begins with" you would use the wildcard ("%
") after the word, but not before. Like what you did for the second query.
Simon Coates
28,694 PointsI tried using the playground at https://teamtreehouse.com/library/sql-basics/finding-the-data-you-want/review-practice-with-sql-playgrounds and I get a bunch of results using:
Select * from actors where name like "will%"
Beginning with alien (case may not matter using like):
SELECT * FROM movies WHERE title LIKE "alien%"
yes 2 is the right answer, you can view the full result set for movies via the playground. Click on movies under the table menu on the left hand side (not the stack icon, which produces a summary of columns). It's a very small set.
Sean Loke
14,659 PointsFor Q1, producing the result "aliens" is fine?
For Q2, im worried im wrong because the set of names which show up include william and willy. What will be the code to specifically produce a set of first names of just Will?
Thanks!
Simon Coates
28,694 Pointsas i said you should be able to see the complete movie table, and it contains alien and aliens (2 applicable records). To get "Will", maybe try "Will %" - that is, include the space. Update: ok, i tried it. If you want will, but not william:
select * from actors where name LIKE "will %"
(nb: best practice would be to capitalize the keywords)
Sean Loke
14,659 PointsThank you for the help!
Sean Loke
14,659 PointsSean Loke
14,659 Pointshttps://teamtreehouse.com/library/sql-basics/finding-the-data-you-want/review-practice-with-sql-playgrounds
Worried about the set of data which my code is producing is not fulfilling the criteria of the question.
Steven Parker
231,271 PointsSteven Parker
231,271 PointsNow that I've seen the playground tasks, it looks like your initial actors query is correct for the task "Find all actors whos first name starts with Will".
But if you want actors whos first name is Will, then as Simon Says ( I couldn't resist) you add the space before the wildcard.
Simon Coates
28,694 PointsSimon Coates
28,694 PointsThe irritating thing about that game is that i was never appointed simon. I guess they were concerned with my existing dangerous tendencies toward meglomania. A preschooler drunk on power is an ugly thing.
Steven Parker
231,271 PointsSteven Parker
231,271 PointsBut doesn't that describe nearly all preschoolers?