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

George Athanasia
George Athanasia
5,750 Points

WHAT AM I MISSING

SELECT Name FROM Fruit UNION SELECT Name FROM Vegetable WHERE Name BETWEEN 'A' AND 'K'

16 Answers

Alexander Nikiforov
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 Points

First 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';
Allan Oloo
Allan Oloo
8,054 Points

why did this not work?

SELECT name FROM Fruit UNION SELECT name FROM Vegetable WHERE Name BETWEEN 'A' AND 'K';
Nassir ALGhumlasi
Nassir ALGhumlasi
4,529 Points

SELECT Name FROM Fruit WHERE Name >= "A" AND Name <= "L" UNION SELECT Name FROM Vegetable WHERE Name >= "A" AND Name <= "L";

this is the correct answer

select Name from Fruit UNION select Name from Vegetable;

This is, indeed, the correct answer. Thank you!

George Athanasia
George Athanasia
5,750 Points

THANK YOU VERY MUCH. I VE TRIED ALL THE SUGGESTIONS EXCEPT ....AND 'L' THAT WAS MY MISTAKE

So how does your code look like now?

Never 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
Andi Muskaj
1,665 Points

If 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';

This 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
George Athanasia
5,750 Points

it 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
Andreas Frost Nordstrøm-Hansen
2,443 Points
SELECT * 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
George Athanasia
5,750 Points

not again! Something wrong is going on with the work checker and i cant go to the next excercise

John Yzaguirre
John Yzaguirre
22,025 Points
SELECT 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
Juan Tirado
3,287 Points

SELECT Name FROM Fruit UNION SELECT Name FROM Vegetable ORDER BY Name ASC LIMIT 79;

blake roeder
blake roeder
1,541 Points

I am having this same issue. Did anyone solve this?

Charles Kubasta
Charles Kubasta
17,288 Points

This 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
stanislavtsv
7,288 Points

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

I 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'

SELECT 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
Andreas Frost Nordstrøm-Hansen
2,443 Points
SELECT 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.