SQL query to find a list of city names that dont start with vowels

A ^ in regular expressions can have different meanings, depending on its location. When it's the first character in a regex, it refers to the start of the string. But when it's the first character in a set, like [^abc], it means not one of. And when it appears elsewhere, it just refers to the ^ itself.

So you would need something like:

SELECT DISTINCT CITY FROM STATION 
WHERE CITY RLIKE '^[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ].*';

or, just exclude the letters you don't want:

SELECT DISTINCT CITY FROM STATION 
WHERE CITY RLIKE '^[^aeiouAEIOU].*';

select distinct city from station 
where city Not like 'A%' and city Not like 'E%' and city Not like 'I%' and
      city Not like 'o%' and city not like 'U%';

Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. IN ORACLE

select distinct city 
from station 
where regexp_like(city, '^[^aeiouAEIOU]|*[^aeiouAEIOU]$');

In MySQL -

 select distinct city 
 from station 
 where city RLIKE '^[^aeiouAEIOU].*' OR 
 city RLIKE '^.*[^aeiouAEIOU]$';

try this.

SELECT DISTINCT CITY 
FROM STATION 
WHERE CITY NOT RLIKE '^[aeiouAEIOU].*$'

Tags:

Mysql