+ 4

SQL: Query the list of CITY names starting with vowels (a, e, I, o, u) from STATION. Your result cannot contain duplicates.?

my answer: SELECT DISTINCT CITY FROM STATION WHERE CITY LIKE '[aeiou]%'; but it's wrong...any clue coders .?

20th Dec 2016, 6:55 PM
Aakash Yadav
Aakash Yadav - avatar
45 Antworten
+ 12
SELECT DISTINCT CITY FROM STATION WHERE lower(substr(CITY,1,1)) in ('a','e','i','o','u') ;
16th Jun 2019, 7:49 AM
Vikash Gupta
Vikash Gupta - avatar
+ 11
This is the solution that worked for me (if you are using MySQL): SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[aeiou]' Regular expression can be confusing but here is good reference https://www.tutorialspoint.com/mysql/mysql-regexps.htm. So what I have here is select the distinct (different) rows within the city row that is located in (FROM) the Station table and I want the returned values to be only the city names that's first letter is a vowel. So the SELECT DISTINCT will pull no duplicates, the FROM will call the Station table, the WHERE will specify that we are asking for the CITY and the LIKE is asking for the condition matching ^ (which is the beginning of the string) and [aeiou] (which are the letters we are searching for at the beginning of the string). By using the single quotes around our regular expression, we are calling the string literals (or the values that match literally the data we want). Hope this helps someone.
25th Nov 2018, 2:08 PM
Nicole Mayer
Nicole Mayer - avatar
+ 6
SELECT DISTINCT CITY FROM STATION WHERE CITY LIKE 'A%' OR CITY LIKE 'E%' OR CITY LIKE 'I%' OR CITY LIKE 'O%' OR CITY LIKE 'U%';
15th Nov 2018, 3:57 PM
Shreya Patil
Shreya Patil - avatar
+ 5
SELECT CITY FROM STATION where SUBSTR(CITY,1,1) IN('A','E','I','O','U');
9th Nov 2018, 2:20 PM
Arnab Pathak
Arnab Pathak - avatar
+ 2
SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[aeiou]';
19th Jan 2021, 7:24 AM
Rajat Goel
Rajat Goel - avatar
0
but Demeth , I used this on w3schools.org SQL compiler and there it's working nice...try here http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_wildcard_charlist&ss=-1
20th Dec 2016, 7:15 PM
Aakash Yadav
Aakash Yadav - avatar
0
I am a self taught coder..I read from multiple sources .. kindly help me
20th Dec 2016, 7:17 PM
Aakash Yadav
Aakash Yadav - avatar
0
@Demeth multiple like conditions also didnt work for this particular query as you told can you suggest something else?
25th Feb 2017, 3:35 PM
Santosh Barik
Santosh Barik - avatar
0
SELECT DISTINCT city FROM station WHERE city RLIKE '^[aeiouAEIOU].*[aeiouAEIOU]
#x27; It's a regular expression query !!
1st Apr 2017, 2:56 PM
Ansh Chavda
Ansh Chavda - avatar
0
SELECT DISTINCT CITY FROM STATION WHERE CITY LIKE '[AEIOU]%'; /*this will work.*/
19th Apr 2017, 5:03 AM
Hari Narayana Batta
Hari Narayana Batta - avatar
0
SELECT DISTINCT city FROM station WHERE city LIKE 'A%' or city LIKE 'E%' or city LIKE 'I%' or city LIKE 'O%' or city LIKE 'U%'; /*try this*/
28th Sep 2017, 8:04 PM
muneer ahmed
muneer ahmed - avatar
0
select distinct 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 LIKE 'a%' OR city LIKE 'e%' OR city LIKE 'i%' OR city LIKE 'o%' OR city LIKE 'u%'; use the cap and small both. you'll get your answer.
4th Jul 2018, 8:19 AM
Ansuman Padhi
Ansuman Padhi - avatar
0
select distinct 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 like 'A%' or city like 'E%' or city like 'I%' or city like 'O%' or city like 'U%'; //check for both uppercase and lowercase letters
17th Jul 2018, 5:48 AM
Illakia V
Illakia V - avatar
0
select distinct city from station where (city LIKE 'A%' or city LIKE 'E%' OR city LIKE 'I%' OR city LIKE 'O%' OR city LIKE 'U%') and (city LIKE '%a' OR city LIKE '%e' OR city LIKE '%i' OR city LIKE '%o' OR city LIKE '%u'); This will defenitely work for oracle
29th Jan 2019, 10:00 AM
Archiot Anil
0
select distinct city from stations where city like '[aeiou]%'
30th Apr 2019, 10:49 AM
Deepthi Bolisetty
Deepthi Bolisetty - avatar
0
Solution in Oracle: SELECT DISTINCT CITY FROM STATION WHERE REGEXP_LIKE(CITY, '^[AEIOU]');
18th Jul 2019, 4:17 AM
Prashanth Pradeep
Prashanth Pradeep - avatar
0
Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates. Input Format The STATION table is described as follows: where LAT_N is the northern latitude and LONG_W is the western longitude.
16th Sep 2019, 6:06 PM
Gyanendra VISHWAKARMA
0
SELECT DISTINCT CITY FROM STATION WHERE CITY LIKE "a%" OR CITY LIKE "e%" OR CITY LIKE "i%" OR CITY LIKE "o%" OR CITY LIKE "u%"
25th Sep 2019, 5:07 AM
Sagrika Chauhan
Sagrika Chauhan - avatar
0
select distinct city from station where city like 'a%' or city like 'e%' or city like 'i%' or city like 'o%' or city like 'u%';
12th Oct 2019, 2:53 PM
shekhar anand
shekhar anand - avatar