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 trialSaravanan Nagaraj
3,147 PointsBummer! Your UNION queries didn't bring back a union of fruits and veggies!
Question
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 distinct result set of fruit and vegetable names.
Answer:
select FruitID, Name from Fruit UNION select VegetableID, Name from Vegetable;
When I try the above mentioned code it shows up with error
Bummer! Your UNION queries didn't bring back a union of fruits and veggies!
What am i missing.
7 Answers
Steven Parker
231,248 PointsYou may have too many columns.
You didn't link to the challenge, but if it asked you to "Create a distinct result set of fruit and vegetable names.", perhaps it wants only the names and not the ID's.
Ali Al Hudari
9,876 PointsThe answer should be as shown below:
SELECT Name FROM Fruit Union SELECT Name FROM Vegetable;
Kevin Gates
15,053 PointsThe IDs being included will make the UNION not happen because those IDs are separate entities. Therefore if "Tomato" was in both tables but had ID of 22 in Fruits and an ID of 45 in Vegetables then it's considered two different items.
The correct answer is:
SELECT Name FROM Fruit
UNION
SELECT Name FROM Vegetable;
brian patterson
9,509 PointsSO WHAT IS THE CORRECT CODE I TRIED THE SAME THING
Stewart Mandla Kohlisa
11,737 PointsSELECT Name FROM Fruit Union SELECT Name FROM Vegetable;
Saravanan Nagaraj
3,147 PointsHi Steven, This works fine. Thank you so much :)
Oscar Lanzendorf
9,747 PointsThat's the correct code:
select Name from Fruit UNION select Name from Vegetable;
Lucian Rotaru
4,983 PointsSELECT Name FROM Fruit UNION SELECT Name FROM Vegetable;
Saravanan Nagaraj
3,147 PointsSaravanan Nagaraj
3,147 PointsHi Steven, This works fine. Thank you so much :)