BlackCat
BlackCat

Reputation: 2044

Sql query using wildcards

Table : City

+-------+
| Name  |
+-------+
| aaa   |
+-------+
| bbb   |
+-------+
| iii   |
+-------+
| uuu   |
+-------+

Need to output results with city name starts with vowels (a,e,i,o or u)

My Query:-

Select Name 
from City
 where Name like 'a%' 
     or Name like 'e%'
     or Name like 'i%'
     or Name like 'o%'
     or Name like 'u%'

It gives desired results though,is there any other way to use wildcards more better in such case?

Upvotes: 2

Views: 67

Answers (1)

Martin Smith
Martin Smith

Reputation: 452988

You can use the set notation

where Name like '[aeiou]%' 

There is also a range notation '[a-z]' if you want to match any character in a contiguous range but that doesn't help in your case.

Upvotes: 7

Related Questions