A large part of data management is searching, and SELECT occupies a large part of it. SELECT select_expr [,select_expr...] [ FROM table_reference WHERE [where_condition] [GROUP BY {col_name | position} [ASC | DESC],...] [HAVING where_condition] [ORDER BY {col_name | expr | position} [ASC | DESC],...] [LIMIT {[offset,] row_count | row_count OFFSET offset}] ] So how do you write the select_expr query expression? a. Each expression represents a desired column, there must be at least one In the user data table, execute to search only the first two columns root@localhost test>select id,username from user; Of course, the order of the query expressions may be inconsistent with the order in the data table. In this case, the query results will be displayed according to the results of the query expressions, that is, the order of the SELECT query expressions will affect the order of the query results. root@localhost test>select username,id from user; c. The asterisk (*) represents all columns, and table_name.* can represent all columns of the named table. root@localhost test>SELECT * FROM user; root@localhost test>SELECT user.id,user.username FROM user; Since the field name has been specified here, why do we need to specify the name of the data table user in user.id and use.name? Because if there is a multi-table connection, that is, two different tables have the same fields. If you write the field name directly, you may not be able to tell which data table the field belongs to. Therefore, you can distinguish which data table the field belongs to by adding the data table name. d. A query expression can be given an alias using [AS] alias_name root@localhost test>SELECT id AS userID,username AS Uname FROM user; It is found that the original id and username in the table have become userID and Uname, so the alias will also affect the result. Pay attention to the syntax of the alias here. root@localhost test>SELECT id username FROM user; At this time, username appears as an alias for id, that is, if the alias coincides with a real field in the data table, username now refers to the alias rather than the real field. e. Aliases can be used in GROUP BY, ORDER BY or HAVING clauses Summarize The above is the MySQL database SELECT query expression parsing introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Detailed tutorial on installing mysql 5.7.26 on centOS7.4
>>: How to install MySQL 5.7 on Ubuntu and configure the data storage path
1. Absolute path First of all, on the local compu...
Introduction: The configuration of Docker running...
It is also very simple to deploy Django projects ...
This article example shares the specific code of ...
CI/CD Overview CI workflow design Git code versio...
Mysql is a popular and easy-to-use database softw...
Table of contents Preface Creating a component li...
Table of contents Events in js Event Type Common ...
I used the label tag when I was doing something re...
Document hints using the show-header attribute sh...
Goal: Create a square whose side length is equal ...
Table of contents nextTick v-model syntax sugar ....
Table of contents 1. Security issues with Docker ...
Effect Need environment vue elementUI Drag and dr...
stat function and stat command Explanation of [in...