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 trialTsung-Lin Chuang
1,567 Pointshow to union two different table and result only shows name with the letter L to Z
how to union two different table and result only shows name with the letter L to Z
2 Answers
Steven Parker
231,248 PointsIn your WHERE
clause, you can use inequality operators on string fields. For example, if compared a field named "word" using the expression "WHERE word < 'L'
", you would get only words that start with letters that come before "L" in the alphabet ("A" through "K").
For more specific help, always show your code and also provide a link the course page you are working with.
Tsung-Lin Chuang
1,567 Pointsdoesn't work. question: there are two table: fruit table with fruitid and name column, vegetable table with vegetableid and name column. create a list of all fruits and vegetables starting with the letters A through K.
my answer is following select name from fruit union select name from vegetable where name >= 'K'
but it doesn't work
Steven Parker
231,248 PointsBut you originally asked for only names "with the letter L to Z". Check my answer again, I revised the example to fit this new criteria.
Eli De Leon
Courses Plus Student 1,758 PointsEli De Leon
Courses Plus Student 1,758 PointsThank you, that worked. I had tried:
SELECT Name FROM Fruit WHERE Name IN ('A%','B%','C%', 'D%', 'E%', 'F%', 'G%', 'H%', 'I%', 'J%', 'K%') UNION SELECT Name FROM Vegetable WHERE Name IN ('A%','B%,'C%', 'D%', 'E%', 'F%', 'G%', 'H%', 'I%', 'J%', 'K%') ORDER BY Name;
as well as trying to use
WHERE Name BETWEEN 'A' AND 'L'
Surprisingly those didnt work.
Steven Parker
231,248 PointsSteven Parker
231,248 PointsYou can't use wildcards with "
IN
", they only work with "LIKE
".