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 trialRobert Close
3,383 PointsNoticed something odd
I'm a bit further along in the SQL lessons but I just noticed something I don't understand dealing with this portion of information. Using the SQL query, SELECT column_name FROM table_name WHERE columnX = "Alien"; works fine. But using the SQL query, SELECT column_name FROM table_name WHERE columnX = "Star Fighter"; does not. I can't seem to make it work for any string that has any spaces in it. Why is that?
Note: putting something in between greater then and less then makes them go poof.
Robert Close
3,383 PointsStill doing the same thing. Not too worried about it as I know how to work around it but like I said I just found it odd.
Jason Anello
Courses Plus Student 94,610 PointsWhich table are you trying to run this query on? Is it something from one of the sql playgrounds?
2 Answers
andi mitre
Treehouse Guest TeacherHey Robert, try it with quotes around the string
select * from movies where title = 'Star Fighter';
Additionally, when working with strings you can always use wildcards (%) this link will show you the differences between '%star', '%star%' and 'star%'.
Hope that helps,
Cheers
Robert Close
3,383 PointsWhoops, forgot to put the quotes in my question. The query itself has them in it. Will edit the question if I can.
As far as wildcards (and LIKE I suppose) are concerned I know how to use them but I thought it odd that I'd have to use them at all in the case I described.
Steven Parker
231,268 PointsA query like SELECT FROM WHERE = Alien
should NOT work, for four reasons:
- there is no column list (or *) in the SELECT clause
- there is no table in the FROM clause
- there is no column mentioned in the WHERE clause
- the string being tested is not in quotes
Quotes should be used around all literal strings, whether or not they contain spaces.
A correct version of that query might be:
SELECT * FROM movies WHERE title = 'Alien';
Robert Close
3,383 Points! I...just wow. I know these things but yet just typed them in wrong on the question. (Sigh) lemme fix it.
Steven Parker
231,268 PointsSteven Parker
231,268 PointsTo prevent the magic vanishing act and show the < symbol use <.
Now that you "fixed" your question.. it looks like both cases should work! Are you still having a problem?