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

Data Analysis

stuck in SQL (Union) task

my following code is not working

select * from Fruit where Name >= 'A' AND Name <= 'K' union select * from Vegetable where Name >= 'A' AND Name <= 'K';

2 Answers

Steven Parker
Steven Parker
230,995 Points

When you use "Name <= 'K'" as a filter, you're accepting names that come before "K" in the alphabet, and the letter "K" itself. If you want the results to include all words that begin with "K", use "Name < 'L'" as the filter instead.

Also, you're not likely to encounter words that come before "A" in the alphabet, so you probably don't need the other filter at all.

select * from Fruit where Name < 'L' union select * from vegetable where Name < 'L';

Still not working .. I want to query all the names from 'A' through 'K' Can you show me the exact code?

Steven Parker
Steven Parker
230,995 Points

In that case, select name instead of *.

If that doesn't solve it (and for future questions) please provide a link to the course page.

I worked Thanks!