11.21 MySQL learning records and 11.21mysql records
2017-11-21 17:51:04
Select *
From world. city;
Select countrycode
From world. city;
/* The distinct keyword applies to all columns, not just the column following */
Select distinct countrycode
From world. city;
/* Retrieve the first five rows of Data */
Select district
From world. city
Limit 5;
/* Search for five rows of data starting from row 10 */
Select district
From world. city
Limit 10, 5;
/* In alphabetical order */
Select Name
From world. city
Order by name;
/* Sort by GNP first and then by Continent (order by 2 and 3 can achieve the same effect, but it is prone to errors when changing )*/
Select name, GNP, Continent
From world. country
Order by GNP, Continent;
/* To perform descending order on multiple columns, add desc after the target column */
Select name, region, population
From world. country
Order by population desc;
/* The order by statement must be placed after the where statement */
Select name, region, population
From world. country
Where population> = 1000000
Order by population;
Select name, region, population
From world. country
Where population between 5000000 and 10000000;
/* The and keyword links two conditions or the keyword meets one of the conditions to return data */
Select name, district, population
From world. city
Where CountryCode = 'phl' and Population> = 400000
/* Brackets should be used to use the where clause with the or and operator at any time )*/
Select name, district, population
From world. city
Where (CountryCode = 'phl' or CountryCode = 'bra ')
And Population >=400000