当前位置:网站首页>MySQL tutorial 66 data table query statement
MySQL tutorial 66 data table query statement
2022-07-25 15:56:00 【51CTO】
stay MySQL in , have access to SELECT Statement to query data . Querying data refers to retrieving data from the database according to requirements , Use different query methods to obtain different data , Is the most frequently used 、 The most important operation .
SELECT The syntax of is as follows :


View Code
among , The meanings of each clause are as follows :
-
{*|< Field column name >} List of fields containing asterisk wildcards , Indicates the name of the field to be queried . -
< surface 1>,< surface 2>…, surface 1 And table 2 Indicates the source of query data , It can be one or more . -
WHERE < expression > Optional. , If you select this item , The query data must meet the query condition . -
GROUP BY< Field >, This clause tells MySQL How to display the queried data , And group according to the specified fields . -
[ORDER BY< Field >], This clause tells MySQL In what order are the queried data displayed , You can sort in ascending order (ASC) And descending (DESC), By default, it is in ascending order . -
[LIMIT[<offset>,]<row count>], This clause tells MySQL Display the number of queried data each time .
Here are some simple SELECT sentence , About WHERE、GROUP BY、ORDER BY and LIMIT And so on , I'll explain them one by one later .
Query all fields in the table
Query all fields refers to the data of all fields in the query table .MySQL The following are provided 2 There are three ways to query all fields in the table .
- Use “*” Wildcard Queries all fields
- List all the fields of the table
1) Use “*” All fields of the query table
SELECT have access to “*” Look up the data of all fields in the table , The syntax is as follows :
Use “*” When inquiring , It can only be arranged in the order of the fields in the data table , You cannot change the order of fields .
example 1
from tb_students_info Query the data of all fields in the table ,SQL The statement and run result are as follows .
Results show , Use “*” When a wildcard is used , All columns will be returned , The data columns are displayed in the order in which the table was created .
2) List all the fields of the table
SELECT The field name after the keyword is the field to be searched , Therefore, the names of all fields in the table can be followed by SELECT After keyword . If you forget the field name , have access to DESC Command to view the structure of the table .
Sometimes , Because there are many fields in the table , You may not remember the names of all fields , Therefore, this method is very inconvenient , Not recommended .
example 2
Inquire about tb_students_info All the data in the table ,SQL The statement can also be written as follows :
Running results and examples 1 identical .
This query method is more flexible , If you need to change the order of field display , Just adjust SELECT The list order of the fields after the keyword is ok .
Although the way to list all the fields of the table is flexible , However, when querying all fields, we usually use “*” wildcard . Use “*” This is the easy way , Especially when there are many fields in the table , The advantages of this method are more obvious . Of course , If you need to change the order of field display , You can choose to list all fields of the table .
The fields specified in the query table
The syntax format of a field in the query table is :
example 3
Inquire about tb_students_info In the table name List the names of all students ,SQL The statement and run result are as follows .
The output shows tb_students_info In the table name All data under field .
Use SELECT Declare that you can get data under multiple fields , Just in the keyword SELECT Specify the name of the field to be found later , Use commas between different field names “,” Separate , There is no need to add a comma after the last field , The syntax is as follows :
example 4
from tb_students_info Table acquisition id、name and height The three column ,SQL The statement and run result are as follows .
The output shows tb_students_info In the table id、name and height All data under the three fields .
边栏推荐
- How matlab saves all the data after running
- Data system partition design - partition and secondary index
- Solve the vender-base.66c6fc1c0b393478adf7.js:6 typeerror: cannot read property 'validate' of undefined problem
- 【IJCAI 2022】参数高效的大模型稀疏训练方法,大幅减少稀疏训练所需资源
- 行云管家V6.5.1/2/3系列版本发布:数据库OpenAPI能力持续强化
- Pat class a topic directory
- 「数字安全」警惕 NFT的七大骗局
- Pytoch learning notes -- seresnet50 construction
- 2019 Zhejiang race c-wrong arrangement, greedy
- Pytoch framework exercise (based on kaggle Titanic competition)
猜你喜欢

Are you ready to break away from the "involution circle"?

LeetCode - 362 敲击计数器(设计)

Geogle Colab笔记1--运行Geogle云端硬盘上的.py文件

Phased summary of the research and development of the "library management system -" borrowing and returning "module

Pytorch学习笔记-Advanced_CNN(Using Inception_Module)实现Mnist数据集分类-(注释及结果)

LeetCode - 359 日志速率限制器 (设计)

Redis分布式锁,没它真不行

HDD Hangzhou station · harmonyos technical experts share the features of Huawei deveco studio

LeetCode - 225 用队列实现栈

LeetCode - 232 用栈实现队列 (设计 双栈实现队列)
随机推荐
JVM knowledge brain map sharing
Alibaba's internal "100 billion level concurrent system architecture design notes" are all inclusive, too comprehensive
MySQL教程71-WHERE 条件查询数据
如何实现页面包含
Pytorch框架练习(基于Kaggle Titanic竞赛)
Understanding the difference between wait() and sleep()
Binary complement
Pat grade a 1153 decode registration card of PAT (25 points)
ML - Speech - traditional speech model
兆骑科创海内外高层次创新创业人才服务平台,双创成果转化平台
< stack simulation recursion >
Pytorch学习笔记-Advanced_CNN(Using Inception_Module)实现Mnist数据集分类-(注释及结果)
SQL cultivation manual from scratch - practical part
Idea - click the file code to automatically synchronize with the directory
Gary Marcus: 学习语言比你想象的更难
MATLAB optimization tool manopt installation
2016 CCPC network trial c-change root DP good question
Are you ready to break away from the "involution circle"?
推荐系统-协同过滤在Spark中的实现
哪里有搭建flink cdc抽mysql数的demo?