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

Hannah Tucker McLellan
Hannah Tucker McLellan
1,856 Points

Why doesn't my query work? Name of Fruit and Veg between A - K

I've tried various combinations of something like this:

SELECT Name FROM Fruit UNION SELECT Name FROM Vegetable WHERE Name >= 'A' AND Name <= 'K'

Try using the BETWEEN operator, and remember this will not include the right range so go to 'L'

2 Answers

So this for conciseness

SELECT name FROM Fruit WHERE name between "A" AND "L"
UNION
SELECT name FROM Vegetable WHERE name between "A" AND "L"
Tristan Magpantay
seal-mask
.a{fill-rule:evenodd;}techdegree
Tristan Magpantay
Full Stack JavaScript Techdegree Student 14,032 Points

you can try something like this

SELECT name FROM fruit WHERE(LEFT(name,1) >= "a" AND LEFT(name,1) <= "k")
UNION
SELECT name FROM vegetable WHERE (LEFT(name,1) >= "a" AND LEFT(name,1) <= "k")
Hannah Tucker McLellan
Hannah Tucker McLellan
1,856 Points

This made me realise why my query was obviously not working. Thanks!!