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

How do I filter query results between a range of starting letters?

SELECT Fruit.Name FROM Fruit
UNION
SELECT Vegetable.Name FROM Vegetable
WHERE Name <= 'K%';

I know there's something I'm missing about this challenge, but why isn't the above acceptable?

I've tried with the WHERE clause after both SELECT statements but that is incorrect as well. I'm not sure which operator works best for a range of starting letters. BETWEEN? LIKE?

Thanks in advance for any help.

1 Answer

alastair cooper
alastair cooper
30,617 Points
select employee_name
from employees
where employee_name LIKE 'A%' OR employee_name LIKE 'B%'

That is a quick way if your range is 2 or 3 letters

if you have a large range (ie A-M) then there is probably a better way

something like this...

SELECT *
FROM Employee
WHERE Name LIKE '[A-E]%';

The exact syntax will depend on version of SQL (mySql, Sql Server, etc)

Hope this helps

alastair cooper
alastair cooper
30,617 Points

oops, sorry, I didn't realise it was for a challenge question! However, the principle should hold, just replace the variables