Question: Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates.
Solution I tried but failed (giving incorrect output):
SELECT DISTINCT city FROM station
WHERE NOT REGEXP_LIKE(city, '^(a|e|i|o|u).*(a|e|i|o|u)$','i');
Solution which worked:
SELECT DISTINCT city FROM station
WHERE REGEXP_LIKE(city, ^[^aeiou].*[^aeiou]$,'i');
Please can anyone explain why the first solution is failing.
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
SELECT
DISTINCT station.city
FROM
station
WHERE
NOT REGEXP_LIKE(station.city, '^(a|e|i|o|u).*(a|e|i|o|u)$', 'i')