DEV Community

Sharmila devi
Sharmila devi

Posted on

basic select sql queries

Query all columns for a city in CITY with the ID 1661

select * From city where id=1661;

Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA.

Select * From city where COUNTRYCODE = 'USA' and population > 100000;

Query all attributes of every Japanese city in the CITY table. The COUNTRYCODE for Japan is JPN.

select * from city where countrycode = 'JPN';

Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.

select count(city) - count(distinct city) from station;

*Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA.
*

select NAME from city where COUNTRYCODE = 'USA' and POPULATION > 120000;

Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN.

Select name from city where countrycode = 'JPN';

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 upper(left(city,1)) NOT IN ('A','E','I','O','U');

*Query all columns (attributes) for every row in the CITY table.
*

select * from city;

*Query a list of CITY and STATE from the STATION table.
*

select city,state from station;

Top comments (0)