摘自SQL-92 语法,摘自 SQL-92 标准并带有超链接:
<direct select statement: multiple rows> ::= <query expression> [ <order by clause> ]
<query expression> ::= <non-join query expression> | <joined table>
<non-join query expression> ::=
<non-join query term>
| <query expression> UNION [ ALL ] [ <corresponding spec> ] <query term>
| <query expression> EXCEPT [ ALL ] [ <corresponding spec> ] <query term>
<joined table> ::=
<cross join>
| <qualified join>
| <left paren> <joined table> <right paren>
<non-join query term> ::=
<non-join query primary>
| <query term> INTERSECT [ ALL ] [ <corresponding spec> ] <query primary>
<query term> ::= <non-join query term> | <joined table>
<cross join> ::=
<table reference> CROSS JOIN <table reference>
<qualified join> ::=
<table reference> [ NATURAL ] [ <join type> ] JOIN <table reference> [ <join specification> ]
<non-join query primary> ::= <simple table> | <left paren> <non-join query expression> <right paren>
<query primary> ::= <non-join query primary> | <joined table>
<table reference> ::=
<table name> [ <correlation specification> ]
| <derived table> <correlation specification>
| <joined table>
<simple table> ::=
<query specification>
| <table value constructor>
| <explicit table>
<query specification> ::=
SELECT [ <set quantifier> ] <select list> <table expression>
<table expression> ::=
<from clause>
[ <where clause> ]
[ <group by clause> ]
[ <having clause> ]
<direct select statement: multiple rows> 是我们将要匹配的规则。我们检查
SELECT * FROM p
匹配 <query specification>、<simple table>、<non-join query primary>、<non-join query term>、<non-join query expression>、<query expression>
SELECT * FROM p UNION SELECT * FROM q
匹配 <非连接查询表达式>
(SELECT * FROM p UNION SELECT * FROM q)
匹配 <non-join query primary>、<non-join query term>、<non-join query expression>、<query expression>
(SELECT * FROM p UNION SELECT * FROM q) UNION SELECT * FROM r
现在匹配 <non-join query expression> 和 <query expression>。
因此它匹配 <direct select statement: multiple rows>,因此它是一个有效的 SQL-92 语句。
类似地,SELECT * FROM p UNION (SELECT * FROM q UNION SELECT * FROM r)
、(SELECT * FROM p)
和(SELECT * FROM p UNION SELECT * FROM q)
evenp CROSS JOIN q
是有效的 SQL-92 选择语句。