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

Create a list of all fruits and vegetables starting with the letters A through K . SQL Fails

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.

SELECT Name FROM Fruit
WHERE Name NOT LIKE '[L-Z]%'
UNION
SELECT Name FROM Vegetable
WHERE Name NOT LIKE '[L-Z]%'

I'm not on this track so I don't know if this is in context. Have you tried just doing one part of the query at a time? Are the names upper case?

SELECT Name
FROM Fruit
WHERE Name NOT LIKE 'A%'
UNION
SELECT Name
FROM Vegetable
WHERE Name NOT LIKE 'A%'

3 Answers

Andreas Frost Nordstrøm-Hansen
Andreas Frost Nordstrøm-Hansen
2,443 Points

It needs to look like this.

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

use L because otherwise it wont take K with it

Thanks worked great..

Though you can use the BETWEEN keyword, one of the examples that he used during this video set included a less than or greater than operator. I was able to answer the question using this code:

SELECT name FROM fruit 
   WHERE name < "L" 
UNION SELECT name FROM vegetable
   WHERE name < "L";
Christopher Phillips
Christopher Phillips
10,061 Points

Why wouldn't the following also work?

SELECT name FROM fruit 
   WHERE name <= "K" 
UNION SELECT name FROM vegetable
   WHERE name <= "K";

Logically, it's still satisfying the requirement. Perhaps the application is not set up to receive that answer.