Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mysql

I'm trying to query the list of CITY names from table - STATION that do not start with vowels with results that cannot contain duplicates. The table just has id, city, population

This is the query that I've written

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

This gives a wrong answer. What am I doing wrong here?

like image 409
Zeus Avatar asked Apr 14 '16 21:04

Zeus


2 Answers

try this.

SELECT DISTINCT CITY 
FROM STATION 
WHERE CITY NOT RLIKE '^[aeiouAEIOU].*$'
like image 172
Tin Tran Avatar answered Oct 07 '22 01:10

Tin Tran


I tried this.

select distinct city
from station
where substring(city,1,1) not in('A','E','I','O','U');
like image 43
Makhmud Galy Avatar answered Oct 06 '22 23:10

Makhmud Galy