Skip to content Skip to sidebar Skip to footer

Get City Name Either Do Not Start With Vowels Or Do Not End With Vowels

Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. Your result cannot contain duplicates. Input Format The STATION table is d

Solution 1:

Assuming you are using MySQL, Here is what you are looking for

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

Footnote : RLIKE and DISTINCT

Solution 2:

SELECTDISTINCT city FROM station WHERE city RLIKE '^[^aeiouAEIOU].* 
 [^aeiouAEIOU]$';

You have to place caret character inside square brackets which means not any vowels. Here is explanation

Solution 3:

SELECTDISTINCT city
FROM   station
WHERE  city REGEXP '^[^aeiouAEIOU]|[^aeiouAEIOU]$'

Solution 4:

This SQL Query will helpful for you. If you are using MS SQL then follow this line of code given below:

SELECTDISTINCT CITY 
FROM STATION  
WHERE CITY NOTLIKE'[AEIOU]%'OR CITY NOTLIKE'%[aeiou]';

If you are using MySQL then follow this line of code given below:

SELECTDISTINCT CITY 
FROM STATION 
WHERE (CITY NOTIN (SELECTDISTINCT CITY FROM STATION WHERE CITY LIKE'%a'OR CITY LIKE'%e'OR CITY LIKE'%i'OR CITY LIKE'%o'OR CITY LIKE'%u'))
OR 
(CITY NOTIN (SELECT CITY FROM STATION WHERE CITY LIKE'A%'OR CITY LIKE'E%'OR CITY LIKE'I%'OR CITY LIKE'O%'OR CITY LIKE'U%'));

Solution 5:

Try the following:

SELECT city 
FROM station 
WHEREleft(city,1) not regexp 'a|e|i|o|u'orright(city,1) not regexp 'a|e|i|o|u'GROUPBY city

Post a Comment for "Get City Name Either Do Not Start With Vowels Or Do Not End With Vowels"