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

Bummer! 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
Steven Parker
231,140 Points

:point_right: You 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.

Hi Steven, This works fine. Thank you so much :)

The answer should be as shown below:

SELECT Name FROM Fruit Union SELECT Name FROM Vegetable;

Kevin Gates
Kevin Gates
15,053 Points

The 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;

SO WHAT IS THE CORRECT CODE I TRIED THE SAME THING

SELECT Name FROM Fruit Union SELECT Name FROM Vegetable;

Hi Steven, This works fine. Thank you so much :)

Oscar Lanzendorf
Oscar Lanzendorf
9,747 Points

That's the correct code:

select Name from Fruit UNION select Name from Vegetable;

SELECT Name FROM Fruit UNION SELECT Name FROM Vegetable;