Databases Querying Relational Databases Set Operations Set Operations

Angyal István
Angyal István
9,196 Points

how to limit results in a string range [e.g. show all names with starting letter from 'a' to 'k']?

--my query, the challenge task says this is not the solution Thanks for the help.

Angyal István
Angyal István
9,196 Points

select name from fruit union select name from vegetable where name like 'a%' or name like 'b%' or name like 'c%' or name like 'd%' or name like 'e%' or name like 'f%' or name like 'g%' or name like 'h%' or name like 'i%' or name like 'j%' or name like 'k%' order by name asc ;

2 Answers

Angyal István
Angyal István
9,196 Points

i have the solution: i should write the where clause for each table

the correct query: select name from fruit where name like 'a%' or name like 'b%' or name like 'c%' or name like 'd%' or name like 'e%' or name like 'f%' or name like 'g%' or name like 'h%' or name like 'i%' or name like 'j%' or name like 'k%' union select name from vegetable where name like 'a%' or name like 'b%' or name like 'c%' or name like 'd%' or name like 'e%' or name like 'f%' or name like 'g%' or name like 'h%' or name like 'i%' or name like 'j%' or name like 'k%' order by name asc ;

KRIS NIKOLAISEN
KRIS NIKOLAISEN
53,478 Points

That seems like a lot of work. You can use greater than on less than symbols with the alphabet to specify a range.