MySQL basics and Database II

MySQL basics and Database Continue..

Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically.
MySQL basics and Database

Select city,length(city) from station where length(city) =(select min(length(city)) from station ) order by city limit 1;

select city,length(city) from station where length(city) =(select max(length(city)) from station) order by city

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

select distinct CITY from STATION where CITY RLIKE '^[AEIOU]'

Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates.

select distinct CITY from STATION where CITY RLIKE '[AEIOU]$'

Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates.

select distinct CITY from STATION where CITY RLIKE '^[AEIOU]' and  CITY RLIKE '[AEIOU]$' 

Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates.

select distinct city from station where CITY RLIKE '^[^AEIOU]'

Query the list of CITY names from STATION that do not end with vowels. Your result cannot contain duplicates.

select distinct city from station where CITY RLIKE '[^AEIOU]$'

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.

select distinct city from station where CITY RLIKE '^[^AEIOU]' or CITY RLIKE '[^AEIOU]$'

Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates.

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" and  CITY not like "a%" and CITY not like "e%" 
and CITY not like "i%" and CITY not like "o%" and CITY not like 'u%'  order by City;

A web developer(Front end and Back end), and DBA at csdamu.com. Currently working as Salesforce Developer @ Tech Matrix IT Consulting Private Limited. Check me @about.me/s.saifi

One comment: On MySQL basics and Database II

Leave a reply:

Your email address will not be published.