SELECT basics

From SQLZOO
(Redirected from SQLZOO:SELECT basics)
Jump to: navigation, search
Language: English  • Deutsch • 中文
namecontinentarea populationgdp
AfghanistanAsia6522302550010020343000000
AlbaniaEurope28748 2831741 12960000000
AlgeriaAfrica2381741 37100000 188681000000
AndorraEurope46878115 3712000000
AngolaAfrica1246700 20609294 100990000000
....

Introducing the world table of countries

This tutorial introduces SQL. We will be using the SELECT command on the table world:

Summary

The example uses a WHERE clause to show the population of 'France'. Note that strings (pieces of text that are data) should be in 'single quotes';

Modify it to show the population of Germany

SELECT population FROM world
  WHERE name = 'France'
SELECT population FROM world
  WHERE name = 'Germany'

Scandinavia

Checking a list The word IN allows us to check if an item is in a list. The example shows the name and population for the countries 'Luxembourg', 'Mauritius' and 'Samoa'.

Show the name and the population for 'Ireland', 'Iceland' and 'Denmark'.


SELECT name, population FROM world
  WHERE name IN ('Luxembourg', 'Mauritius', 'Samoa');
SELECT name, population FROM world
  WHERE name IN ('Ireland', 'Iceland', 'Denmark');


Just the right size

Which countries are not too small and not too big? BETWEEN allows range checking (range specified is inclusive of boundary values). The example below shows countries with an area of 250,000-300,000 sq. km. Modify it to show the country and the area for countries with an area between 200,000 and 250,000.

SELECT name, area FROM world
  WHERE area BETWEEN 250000 AND 300000


SELECT name, area FROM world
  WHERE area BETWEEN 200000 AND 250000


Language: English  • Deutsch • 中文