I want to query the list of CITY
names from the table STATION(id, city, longitude, latitude)
which have vowels as both their first and last charact
My simple solution :::
SELECT DISTINCT CITY
FROM STATION
WHERE CITY LIKE '[a,e,i,o,u]%[a,e,i,o,u]';
You can use LEFT() and RIGHT() functions. Left(CITY,1)
will get the first character of CITY
from left. Right(CITY,1)
will get the first character of CITY
from right (last character of CITY
).
DISTINCT
is used to remove duplicates. To make the comparison case-insensitive, we will use the LOWER() function.
SELECT DISTINCT CITY
FROM STATION
WHERE LOWER(LEFT(CITY,1)) IN ('a', 'e', 'i', 'o', 'u') AND
LOWER(RIGHT(CITY,1)) IN ('a', 'e', 'i', 'o', 'u')
Try this for beginning with vowel
Oracle:
select distinct *field* from *tablename* where SUBSTR(*sort field*,1,1) IN('A','E','I','O','U') Order by *Sort Field*;
Select distinct(city) from station where city RLIKE '^[aeiouAEIOU]'
Very simple answer.
You could use a regular expression:
SELECT DISTINCT city
FROM station
WHERE city RLIKE '^[aeiouAEIOU].*[aeiouAEIOU]$'
For MS access or MYSQL server
SELECT city FROM station
WHERE City LIKE '[aeiou]%'and City LIKE '%[aeiou]';