简介:
从数据库中检索行,并允许从 SQL Server 2012 中的一个或多个表中选择一个或多个行或列。 虽然 SELECT 语句的完整语法较复杂,但其主要子句可归纳如下:
[ WITH <common_table_expression>] SELECT select_list [ INTO new_table ] [ FROM table_source ] [ WHERE search_condition ] [ GROUP BY group_by_expression] [ HAVING search_condition] [ ORDER BY order_expression [ ASC | DESC ] ]
可在查询之间使用 UNION、EXCEPT 和 INTERSECT 运算符,以便将各个查询的结果合并或比较到一个结果集中。
语法:
<SELECT statement> ::= [WITH <common_table_expression> [,...n]] <query_expression> [ ORDER BY { order_by_expression | column_position [ ASC | DESC ] } [ ,...n ] ] [ <FOR Clause>] [ OPTION ( <query_hint> [ ,...n ] ) ] <query_expression> ::= { <query_specification> | ( <query_expression> ) } [ { UNION [ ALL ] | EXCEPT | INTERSECT } <query_specification> | ( <query_expression> ) [...n ] ] <query_specification> ::= SELECT [ ALL | DISTINCT ] [TOP ( expression ) [PERCENT] [ WITH TIES ] ] < select_list > [ INTO new_table ] [ FROM { <table_source> } [ ,...n ] ] [ WHERE <search_condition> ] [ <GROUP BY> ] [ HAVING < search_condition > ]