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 trialGeorge Athanasia
5,750 PointsWHAT AM I MISSING
SELECT Name FROM Fruit UNION SELECT Name FROM Vegetable WHERE Name BETWEEN 'A' AND 'K'
16 Answers
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsFirst of all you have to select ONLY names from Fruit
and Vegetable
table.
This transforms query to:
SELECT name FROM Fruit UNION SELECT name FROM Vegetable WHERE Name BETWEEN 'A' AND 'K';
Second, you have to select both Vegetables from 'A' to 'K' and fruits from 'A' to 'K'. That is why put WHERE
for Fruit
table as well
SELECT name FROM Fruit
WHERE name BETWEEN 'A' AND 'K'
UNION
SELECT name FROM Vegetable
WHERE Name BETWEEN 'A' AND 'K';
That however will not work, because BETWEEN will not include fruits or vegetables with letter 'K', because of the BETWEEN syntax.
That is why you have to change 'A' AND 'K'
to 'A' to 'L'
.
Which bring you to final query:
SELECT name FROM Fruit
WHERE name BETWEEN 'A' AND 'L'
UNION
SELECT name FROM Vegetable
WHERE Name BETWEEN 'A' AND 'L';
Nassir ALGhumlasi
4,529 PointsSELECT Name FROM Fruit WHERE Name >= "A" AND Name <= "L" UNION SELECT Name FROM Vegetable WHERE Name >= "A" AND Name <= "L";
cossy
17,748 Pointsthis is the correct answer
select Name from Fruit UNION select Name from Vegetable;
Riley Egan
2,452 PointsThis is, indeed, the correct answer. Thank you!
George Athanasia
5,750 PointsTHANK YOU VERY MUCH. I VE TRIED ALL THE SUGGESTIONS EXCEPT ....AND 'L' THAT WAS MY MISTAKE
Werner Bergh
5,995 PointsSo how does your code look like now?
Werner Bergh
5,995 PointsNever mind I got it thanks
SELECT Name FROM Fruit WHERE Name BETWEEN "A" AND "L" UNION SELECT Name FROM Vegetable WHERE Name BETWEEN "A" AND "L";
Andi Muskaj
1,665 PointsIf using BETWEEN is a little confusing for you like it was for me, try this:
SELECT name FROM fruit WHERE name < 'L'
UNION
SELECT name FROM vegetable WHERE name < 'L';
John Vornberger
18,115 PointsThis worked for me with no errors
select distinct name from ( select distinct name from fruit f union select distinct name from vegetable v);
George Athanasia
5,750 Pointsit doesn't work even with a ; (questionmark)
There are two tables Fruit and Vegetable table. The Fruit table has a FruitID and a Name column and the Vegetable table has a VegetableID and Name column. Create a list of all fruits and vegetables starting with the letters A through K . In other words all fruit and vegetables that don't start with the letter L to Z.
Andreas Frost Nordstrøm-Hansen
2,443 PointsSELECT * FROM Fruit UNION SELECT * FROM Vegetable WHERE Name BETWEEN 'A' AND 'K';
im not sure but i think it wants you to return id alongside it aswell. Try this maybe?
George Athanasia
5,750 Pointsnot again! Something wrong is going on with the work checker and i cant go to the next excercise
John Yzaguirre
22,025 PointsSELECT Name
FROM Fruit
WHERE SUBSTR(Name, 1, 1) < "L";
UNION
SELECT Name
FROM Vegetable
WHERE SUBSTR(Name, 1, 1) < "L";
Also works but throws an error
Juan Tirado
3,287 PointsSELECT Name FROM Fruit UNION SELECT Name FROM Vegetable ORDER BY Name ASC LIMIT 79;
blake roeder
1,541 PointsI am having this same issue. Did anyone solve this?
Charles Kubasta
17,288 PointsThis worked for me.
SELECT Name FROM Fruit WHERE Name BETWEEN 'A' AND 'L' UNION SELECT Name FROM Vegetable WHERE Name BETWEEN 'A' AND 'L';
What issue are you having exactly?
stanislavtsv
7,288 PointsSELECT Name FROM Fruit WHERE Name BETWEEN "A" AND "L" UNION SELECT Name FROM Vegetable WHERE Name BETWEEN "A" AND "L";
John Napier
14,383 PointsI would think this works, but it throws an error:
select Name
From Fruit
where left(Name,1) < 'L'
Union
select Name
From Vegetable
where left(Name,1) < 'L'
Indhira Acevedo
1,894 PointsSELECT Name FROM Fruit WHERE Name BETWEEN "A" AND "L" UNION SELECT Name FROM Vegetable WHERE Name BETWEEN "A" AND "L";
I was doing It just like this only i included A and K as the problem suggested? if L through Z weren't supposed to be included then why is it the correct answer? confused
Andreas Frost Nordstrøm-Hansen
2,443 PointsSELECT Name FROM Fruit UNION SELECT Name FROM Vegetable WHERE Name BETWEEN 'A' AND 'K';
I would put a ; at the end to make sure it's a closed command.
Allan Oloo
8,054 PointsAllan Oloo
8,054 Pointswhy did this not work?
SELECT name FROM Fruit UNION SELECT name FROM Vegetable WHERE Name BETWEEN 'A' AND 'K';