Oracle 5.0 Reference Manual page 1117

Table of Contents

Advertisement

The
statements are normal select statements, but with the following restrictions:
SELECT
• Only the last
SELECT
written to the file.)
cannot be used with
HIGH_PRIORITY
it for the first SELECT, it has no effect. If you specify it for any subsequent
syntax error results.
The default behavior for
keyword has no effect other than the default because it also specifies duplicate-row
DISTINCT
removal. With the optional
all matching rows from all the
You can mix
UNION ALL
such that a
DISTINCT
explicitly by using
UNION DISTINCT
keyword.
To apply
or
ORDER BY
enclose the SELECT:
(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);
However, use of
ORDER BY
the rows appear in the final result because
Therefore, the use of
ORDER BY
used to determine the subset of the selected rows to retrieve for the SELECT, even though it does
not necessarily affect the order of those rows in the final
in a SELECT, it is optimized away because it will have no effect anyway.
LIMIT
To use an
or
ORDER BY
individual
statements and place the
SELECT
example uses both clauses:
(SELECT a FROM t1 WHERE a=10 AND B=1)
UNION
(SELECT a FROM t2 WHERE a=11 AND B=2)
ORDER BY a LIMIT 10;
A statement without parentheses is equivalent to one parenthesized as just shown.
This kind of
ORDER BY
tbl_name.col_name
to the alias in the
ORDER
position. However, use of column positions is deprecated.)
Also, if a column to be sorted is aliased, the
name. The first of the following statements will work, but the second will fail with an
'a' in 'order clause'
(SELECT a AS b FROM t) UNION (SELECT ...) ORDER BY b;
(SELECT a AS b FROM t) UNION (SELECT ...) ORDER BY a;
To cause rows in a
UNION
the other, select an additional column in each
following the last SELECT:
(SELECT 1 AS sort_col, col1a, col1b, ... FROM t1)
SELECT
statement can use
INTO
SELECT
is that duplicate rows are removed from the result. The optional
UNION
keyword, duplicate-row removal does not occur and the result includes
ALL
statements.
SELECT
and
UNION DISTINCT
union overrides any
ALL
or implicitly by using
to an individual SELECT, place the clause inside the parentheses that
LIMIT
for individual
SELECT
UNION
in this context is typically in conjunction with LIMIT, so that it is
clause to sort or limit the entire
LIMIT
ORDER BY
cannot use column references that include a table name (that is, names in
format). Instead, provide a column alias in the first
BY. (Alternatively, refer to the column in the
ORDER BY
error:
result to consist of the sets of rows retrieved by each
1097
Syntax
OUTFILE. (However, the entire
statements that are part of a UNION. If you specify
in the same query. Mixed
union to its left. A
DISTINCT
with no following
UNION
statements implies nothing about the order in which
by default produces an unordered set of rows.
result. If
UNION
UNION
or
after the last one. The following
LIMIT
clause must refer to the alias, not the column
to use as a sort column and add an
SELECT
result is
UNION
statements, a
SELECT
types are treated
UNION
union can be produced
DISTINCT
appears without
ORDER BY
result, parenthesize the
statement and refer
SELECT
using its column
ORDER BY
Unknown column
one after
SELECT
ORDER BY
or
ALL

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents