HP Neoview SQL Reference Manual page 177

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

(The year-month fields are YEAR and MONTH. The day-time fields are DAY, HOUR,
MINUTE, and SECOND.)
For example, suppose that the column in TABLE1 has the data type INTERVAL HOUR TO
MINUTE, and the column in TABLE2 has the data type INTERVAL DAY TO HOUR. The
data type of the column resulting from the union operation is INTERVAL DAY TO MINUTE.
If both columns are described with NOT NULL, the corresponding column of RESULT
cannot be null. Otherwise, the column can be null.
ORDER BY Clause and the UNION Operator
In a query containing a UNION operator, the ORDER BY clause defines an ordering on the result
of the union. In this case, the SELECT statement cannot have an individual ORDER BY clause.
You can specify an ORDER BY clause only as the last clause following the final SELECT statement
(SELECT2 in this example). The ORDER BY clause in RESULT specifies the ordinal position of
the sort column either by using an integer or by using the column name from the select list of
SELECT1.
This SELECT statement shows correct use of the ORDER BY clause:
SELECT A FROM T1 UNION SELECT B FROM T2 ORDER BY A
This SELECT statement is incorrect because the ORDER BY clause does not follow the final
SELECT statement:
SELECT A FROM T1 ORDER BY A UNION SELECT B FROM T2
This SELECT statement is also incorrect:
SELECT A FROM T1 UNION (SELECT B FROM T2 ORDER BY A)
Because the subquery (SELECT B FROM T2...) is processed first, the ORDER BY clause does not
follow the final SELECT.
GROUP BY Clause, HAVING Clause, and the UNION Operator
In a query containing a UNION operator, the GROUP BY or HAVING clause is associated with
the SELECT statement it is a part of (unlike the ORDER BY clause, which can be associated with
the result of a union operation). The groups are visible in the result table of the particular SELECT
statement. The GROUP BY and HAVING clauses cannot be used to form groups in the result of
a union operation.
UNION ALL and Associativity
The UNION ALL operation is left associative, meaning that these two queries return the same
result:
(SELECT * FROM TABLE1 UNION ALL
SELECT * FROM TABLE2) UNION ALL SELECT * FROM TABLE3;
SELECT * FROM TABLE1 UNION ALL
(SELECT * FROM TABLE2 UNION ALL SELECT * FROM TABLE3);
If both the UNION ALL and UNION operators are present in the query, the order of evaluation
is always from left to right. A parenthesized union of SELECT statements is evaluated first, from
left to right, followed by the remaining union of SELECT statements.
Access Modes and the UNION Operator
In a query containing the UNION operator, if you specify an access option for the second operand
before the ORDER BY clause (or if the UNION has no ORDER BY clause) and you do not specify
an option for the first operand, the first operand inherits the session's transaction isolation level
setting. If this setting is different from the one you specified for the second operand, Neoview
SQL issues a warning. For example:
SELECT Statement
177

Advertisement

Table of Contents
loading

Table of Contents