In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article is about how the SQL select syntax works. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
The syntax structure of the select statement in SQL is: "SELECT_list [ INTO..] FROM table_name [ WHERE...] [ GROUP BY...] [ HAVING...] [ ORDER BY...]; "。
SELECT statements consist of a series of flexible clauses that together determine which data to retrieve. SELECT statements allow users to view system information for SQL Server in addition to tables and views in the general database. Before introducing the use of SELECT statements, it is necessary to introduce the basic syntax structure and execution process of SELECT statements.
Syntax structure of SELECT statement
Although the complete syntax of SELECT statements is complex, their main clauses can be summarized as follows:
SELECT select_list[ INTO new_table]FROM table_name[ WHERE search_condition][ GROUP BY group_by_expression][ HAVING search_condition][ ORDER BY order_expression [ ASC|DESC ] ]
The only clauses required are SELECT and FROM clauses; all other clauses are optional. The clauses have the following meanings:
- SELECT clause: Specifies the columns returned by the query.
- INTO clause: Stores the retrieval results in a new table or view.
- FROM clause: Used to specify the table or view in which the referenced column resides. If there is more than one object, they must be separated by commas.
- WHERE clause: Specifies search criteria to limit the rows returned. If the SELECT statement does not have a WHERE clause, the DBMS assumes that all rows in the target table satisfy the search condition.
- GROUP BY clause: Specifies the group in which the output rows are placed, and calculates the summary value for each group if the SELECT clause contains an aggregate function.
- HAVING clause: Specify search criteria for groups or aggregations. HAVING is usually used with a GROUP BY clause. Without a GROUP BY clause, HAVING behaves the same as a WHERE clause.
- ORDER BY clause: Specifies the ordering of the result set. ASC keyword indicates ascending results, DESC keyword indicates descending results. If no keyword is specified, ASC is the default keyword. Without an ORDER BY clause, the DBMS displays the data according to where it is stored in the input table.
SELECT Order and Function of Clauses
The order of clauses in a SELECT statement is important. Optional clauses can be omitted, but they must appear in the proper order when used. Their order and primary role in SELECT query statements are shown in Table 4.1.
Table 4.1 Order and effect of clauses in SELECT query statement
sequence number
clause keyword
clause function
1
SELECT
fetches data for a specified column from a specified table
2
FROM
Specify the table to query for the operation
3
WHERE
Used to specify a criteria for selecting queries
4
GROUP BY
Grouping result sets, often used with aggregate functions
5
HAVING
Returns the number of rows in the selected result set
6
ORDER BY
Specify search criteria for grouping
If some of the query clauses shown in Table 4.1 are used in the same SELECT query statement, the query clauses are arranged in descending order of their ordinal number.
Thank you for reading! About "SQL select syntax structure is what" this article is shared here, I hope the above content can have some help to everyone, so that we can learn more knowledge, if you think the article is good, you can share it to let more people see it!
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.