Sql Query to Check If a Name Begins and Ends With a Vowel

SQL query to check if a name begins and ends with a vowel

You could use a regular expression:

SELECT DISTINCT city
FROM station
WHERE city RLIKE '^[aeiouAEIOU].*[aeiouAEIOU]$'

How to retrieve rows that begin and end with vowels?

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')


Related Topics



Leave a reply



Submit