Databases Querying Relational Databases Set Operations Set Operations

I followed all the examples but I'm getting an error that says the query is not returning through A and K.

Is it my syntax?

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

Steven Parker
Steven Parker
185,909 Points

Show your complete query so we can see.

1 Answer

Steven Parker
Steven Parker
185,909 Points

You're close, but BETWEEN "A" AND "K" would not include any names that begin with "K" unless the name was just the single letter "K" itself.

You might want to make use of an inequality comparison, since they work on dictionary order when used with strings.

Also, I don't think the task asks you to ORDER the results in any particular way.

Thank you. I solved it by using WHERE Name < "L". Could I have used LIKE "A%" AND "K%" also?

Steven Parker
Steven Parker
185,909 Points

That expression isn't complete, but even if you used WHERE Name LIKE "A%" OR Name LIKE "K%" that would only give you names starting with "A" and "K" and nothing in between. Combining with AND would produce no output, because no name could start with both letters.