Databases Querying Relational Databases Set Operations Set Operations

victorvillaplana
victorvillaplana
11,582 Points

Problem with task 2 of 6

I don't know what's the problem with my query:

SELECT Name FROM Fruit WHERE Name BETWEEN "A" AND "K" UNION SELECT Name FROM Vegetable WHERE Name BETWEEN "A" AND "K" ORDER BY Name;

Could you help me? Thanks

2 Answers

Robert Stefanic
Robert Stefanic
34,595 Points

There's a small syntax problem here, but you're on the right track.

You want to select Fruits and Vegetables where the Name is >= a letter and less than or equal to another letter; however, when I tried doing "Name <= 'K', it gave me an error. If I did name < 'L', then everything worked just fine. Even though the former should work, it didn't (for me at least). So the part that checks your input must be very specific.

SELECT Name 
  FROM Fruit 
  WHERE Name >= 'A' AND Name < 'L' 
  UNION 
    SELECT Name 
    FROM Vegetable 
    WHERE Name >= 'A' AND Name < 'L' 
  ORDER BY Name 
victorvillaplana
victorvillaplana
11,582 Points

Thanks Robert!

I tried your query and it worked.