Use the SELECT statement to explore the database

In the previous article, we introduced some important concepts of relational database and SQL language, and prepared the environment and initialization data required by the course. Let us now officially start learning SQL!

Query is the most common operation in the database, so let's first understand the basic query statement.

All SQL statements in this column are applicable to 4 kinds of databases by default, and the database-specific syntax will be specially explained.

Query specified field

In the employee table, information about employees is stored. Assuming that you plan to send mass emails, you need to find out the names, genders, and email addresses of all employees. In SQL can be achieved by a simple query statement:

SELECT emp_name, sex, email
  FROM employee;

SELECT means query, and then lists the fields to be returned. Multiple fields are separated by commas; FROM means which table to query from; semicolon means the end of the SQL statement. The results of the execution of the statement are as follows (part of the data is displayed):

avatar

This kind of operation of the specified fields in the query table is called projection in relational operations, and is represented by the SELECT clause. The projection is a vertical selection for the table, and the required fields are reserved for generating a new table. The following is a schematic diagram of the projection operation:

avatar

The projection operation includes a special operation, which is to query all the fields in the table.

Query all fields

View all fields in the table

Guess you like

Origin blog.csdn.net/horses/article/details/108729116
Recommended