Reputation: 71
Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates.
Upvotes: 1
Views: 1077
Reputation: 28864
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')
Upvotes: 0
Reputation: 38552
You can try using REGEXP
Explanation: The below query will select all the DISTINCT rows where cities starts with a vowel as first characters, followed by any other characters zero or more times and finally also contains a vowel characters at end.
SELECT DISTINCT CITY
FROM STATION
WHERE CITY REGEXP '^[aeiouAEIOU].*[aeiouAEIOU]$'
Upvotes: 1