MySQL database single table query-basic query

Basic query

The basic statement that MySQL queries data from the data table is the SELECT statement. The SELECT statement returns the result of the query in a database. The result is regarded as a collection of records. The query is divided into single-table query and multi-table query.

Create 3 data tables and insert data:
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
stu:
Insert picture description here
emp:
Insert picture description here
dept:
Insert picture description here

1. Query all fields
Query all fields is to query all the data in the table. Use the SELECT statement to query the data in the table in MySQL. The specific syntax format is as follows.

SELECT 字段名1, 字段名2, ... 字段名n FROM 表名;

In the above syntax format, the field name represents the field name in the table, and the table name represents the table name of the query data.
Query all data in the stu table.
Insert picture description here
By changing the position of the field name in the query statement, the order of the query results can be changed.
Insert picture description here
A wildcard character "*" is provided in MySQL. This wildcard character can replace all field names to facilitate writing SQL statements. The specific syntax is as follows:

SELECT * FROM 表名;

Insert picture description here
2. Query specified fields
Most of the time, it is part of the data in the query table. When using the SELECT statement, you can also specify the fields. According to the specified fields, you can query part of the data in the table. The syntax format is as follows:

SELECT 字段名1, 字段名2,...FROM 表名;

Query the sid and sname fields in the stu table.
Insert picture description here

Guess you like

Origin blog.csdn.net/javanofa/article/details/107702172