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 Querying Relational Databases Set Operations Set Operations

Hans Eisenman
Hans Eisenman
1,315 Points

How do you build a Where clause that selects out all words which start with letters A-K?

I'm not sure how to do this and get a syntax error right from the get-go. I've tried a few approaches and this one seems the most logical (code should be attached) but at the same time there must be a better way. I don't recall getting this in earlier SQL lessons, but that doesn't mean it wasn't covered. Calling out for a life line. :)

Hans Eisenman
Hans Eisenman
1,315 Points

I thought Treehouse was going to attach my code but now I don't see it. Here's a snippet of the approach I was taking. Again, this seems like the long way to my destination. Must be a better way!

select name from vegetable 
union 
select name from fruit 
where not like 'L%' 
and not like 'M%' 

[etc. ...]

4 Answers

You can use less than and greater than signs to filter letters alphabetically just like numbers. So

WHERE name < "L"

would be letters A-K

Hans Eisenman
Hans Eisenman
1,315 Points

Thanks Kris! I knew there had to be something more graceful than what I was attempting! :)

Hans Eisenman
Hans Eisenman
1,315 Points

Weird. I can make this WHERE clause work in SQL Serve Mgmt Studio, but I can't get it to work in my Treehouse lesson.

SELECT name FROM fruit
UNION
SELECT name FROM vegetable
WHERE name < 'L'

Error I get is:

Bummer: Your UNION queries didn't bring back a union of fruits and veggies beginning with the letters A through K!

As a side note: I wish it were possible to check one's work in pieces like you can in a regular SQL IDE (select parts of it and Execute it). That way you could use use the process of elimination to narrow down the exact issue.

Your first select statement needs a WHERE clause

Hans Eisenman
Hans Eisenman
1,315 Points

Ah. Of course. Should have thought of that. Many thanks again! I finally got past this one.