The most basic 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
If no where clause exists, 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, containing the expression of the field
Or more complex subqueries.
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