In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the usage of the database query sentence select for you. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The database query statement select is used to select data from a table, and the results are stored in a result table (called the result set); the syntax format is "SELECT [column name] FROM table name [restrictions of the WHERE clause];".
SELECT statement
The SELECT statement is used to select data from a table.
The results are stored in a result table (called a result set).
The syntax format of SELECT is as follows:
SELECT {* |} [FROM, … [WHERE [GROUP BY [HAVING [{} …]] [ORDER BY] [LIMIT [,]
Among them, the meaning of each clause is as follows:
{* |} contains a list of fields with asterisk wildcards, indicating the name of the field to be queried.
,... Tables 1 and 2 represent the sources of query data, which can be single or multiple
WHERE is optional, and if selected, the query data must meet the query criteria.
GROUP BY
< 字段 >That tells MySQL how to display the queried data and group it by the specified field
[ORDER BY
< 字段 >This clause tells MySQL in what order the queried data is displayed, which can be sorted in ascending (ASC) and descending (DESC) order, which is ascending by default.
[LIMIT [,]], this clause tells MySQL to display the number of pieces of data that are queried each time.
Use "*" to query all fields of the table
SELECT can use "*" to find data for all fields in the table. The syntax format is as follows:
SELECT * FROM table name
When using a "*" query, you can only arrange the fields in the order of the data table, not change the order of the fields.
Example 1
Query the data for all fields from the tb_students_info table, and the SQL statement and run results are shown below.
Mysql > use test_db;Database changedmysql > SELECT * FROM tb_students_info +-+ | id | name | dept_id | age | sex | height | login_date | + -+-+ | 1 | Dany | 1 | 25 | F | 2015 | 09-10 | 2 | Green | 3 | 23 | F | 2016-10-22 | 3 | Henry | 2 | 23 | M | 2015-05-31 | 4 | Jane | 1 | 22 | F | 2016-12-20 | 5 | | Jim | 1 | 24 | M | 2016 | 01-15 | | 6 | John | 2 | 21 | M | 2015 | 11-11 | | 7 | Lily | 6 | 22 | F | 2016-02-26 | 8 | Susan | 4 | 23 | F | 2015-10-01 | 9 | Thomas | 3 | 22 | M | 2016-06-07 | | | 10 | Tom | 4 | 23 | M | 165,165 | 2016-08-05 | +-+ 10 rows in set (0.26sec) |
The result shows that when you use the "*" wildcard, all columns are returned, and the data columns are displayed in the order in which the table was created.
Note: in general, it is best not to use the wildcard "*" unless you need to use all the field data in the table. Although using wildcards can save time entering query statements, getting unwanted column data usually reduces the efficiency of the query and the application used. The advantage of using "*" is that when you don't know the names of the columns you want, you can get them through "*".
Query the fields specified in the table
The syntax format for a field in the query table is:
SELECT
< 列名 >FROM
< 表名 >Example 2
Query the names of all the students in the name column in the tb_students_info table, and the SQL statement and run results are shown below.
Mysql > SELECT name FROM tb_students_info;+-+ | name | +-+ | Dany | | Green | | Henry | | Jane | | Jim | | John | | Lily | | Susan | | Thomas | | Tom | +-+ 10 rows in set (0.00 sec)
The output shows all the data under the name field in the tb_students_info table.
You can use the SELECT declaration to obtain the data under multiple fields. You only need to specify the field name to be looked up after the keyword SELECT. Different field names are separated by commas "and". There is no need to add a comma after the last field. The syntax format is as follows:
SELECT,... , FROM
Example 3
Get the id, name, and height columns from the tb_students_info table, and the SQL statement and run results are shown below.
Mysql > SELECT id,name,height-> FROM tb_students_info + -. | 178 | 10 | Tom | 165 | +-+ 10 rows in set (0.00 sec)
The output shows all the data under the id, name, and height fields in the tb_students_info table.
On the database query statement select usage is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.