1. As keyword usage
Syntax format: SELECT field 1 as alias 1, field 2 as alias 2 FROM table name;
Example:
SELECT name as name, age as age FROM member;
Abbreviation syntax: SELECT name name, age age FROM member;
2. How to use the distinct keyword
Usage scenario of the distinct keyword: there is a lot of duplicate data in a field, such as the gender data in the data table. There are only two genders, and there will be a lot of duplicate data. Using the distinct keyword can remove the duplicate data.
Syntax format: SELECT DISTINCT (field name) FROM table name;
Example:
SELECT DISTINCT(gender) FROM member;
Extension: How to query duplicate data of multiple fields? For example, there are many male and female members of the same age among the members. Find out the information of the members whose age has been eliminated?
Syntax: SELECT DISTINCT (age), gender, name FROM member;