The select command or statement is used to obtain record information in one or more tables. It is generally used with the where clause to obtain records that meet certain conditions. If there is no where clause, all records are returned. The general usage is as follows:
SELECT attribute-list FROM table-name WHERE condition |
Attribute-list: list of returned content, separated by commas. The content here can be a field, including the expression of the field or a more complex subquery.
Table-name: name of a table. If it is more complex, it can be a subquery.
Condition: A condition expression used to filter records that meet the condition.
In this section, we use the following table for testing:
| Bbc (name, region, area, population, gdp) |
The table name is bbc. The table has five columns, also known as attribute ).
Name: Country name
Region: region of the country
Area: area
Population: population
Gdp: gdp
SQL instance:
1. Select the names, regions, and population of all countries.
| SELECT name, region, population FROM bbc |
2. Provide the population of France
SELECT population FROM bbc WHERE name = 'France' |
3. Which country names start with the character D?
SELECT name FROM bbc WHERE name LIKE 'd %' |
Iv. Country names and population density of large land countries (with an area greater than 5 million square kilometers)
SELECT name, population/area FROM bbc WHERE area> 5000000 |
V. Countries with small (area less than 2000 square kilometers) and rich (GDP greater than 5 billion)
SELECT name, region FROM bbc WHERE area <2000 AND gdp> 5000000000 |
(