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'

Richard Price
Richard Price
17,069 Points

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

2 Answers

Tristan Magpantay
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!!

Richard Price
Richard Price
17,069 Points

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"