Databases Querying Relational Databases Set Operations Set Operations

Melina Whitlock
Melina Whitlock
2,977 Points

I am confused on how to use BETWEEN an LIKE in the same UNION query statement

SELECT Name FROM Fruit UNION SELECT Name FROM Vegetable WHERE Name BETWEEN LIKE A% AND L%;

2 Answers

Steven Parker
Steven Parker
203,206 Points

You can't combine LIKE and BETWEEN, but I'd guess you don't need either. You didn't show the instructions, but assuming they have asked you for names that start with A up through L, you can use an inequality test:

... WHERE name < 'N'

Also be sure to give each SELECT it's own WHERE clause.

Melina Whitlock
Melina Whitlock
2,977 Points

Thank you! I actually ended up doing that exact thing.