Oracle 5.0 Reference Manual page 1121

Table of Contents

Advertisement

SELECT s1 FROM t1 WHERE s1 <> SOME (SELECT s1 FROM t2);
Use of the word
English phrase "a is not equal to any b" means "there is no b which is equal to a," but that is not what is
meant by the SQL syntax. The syntax means "there is some b to which a is not equal." Using
instead helps ensure that everyone understands the true meaning of the query.
13.2.9.4. Subqueries with
Syntax:
operand comparison_operator
The word ALL, which must follow a comparison operator, means "return
for
TRUE
ALL
SELECT s1 FROM t1 WHERE s1 > ALL (SELECT s1 FROM t2);
Suppose that there is a row in table
(-5,0,+5)
contains
(12,6,NULL,-100)
The expression is unknown (that is, NULL) if table
Finally, the expression is
is empty:
SELECT * FROM t1 WHERE 1 > ALL (SELECT s1 FROM t2);
But this expression is
SELECT * FROM t1 WHERE 1 > (SELECT s1 FROM t2);
In addition, the following expression is
SELECT * FROM t1 WHERE 1 > ALL (SELECT MAX(s1) FROM t2);
In general, tables containing
subqueries, always consider whether you have taken those two possibilities into account.
is an alias for
NOT IN
SELECT s1 FROM t1 WHERE s1 <> ALL (SELECT s1 FROM t2);
SELECT s1 FROM t1 WHERE s1 NOT IN (SELECT s1 FROM t2);
13.2.9.5. Row Subqueries
The discussion to this point has been of scalar or column subqueries; that is, subqueries that return a
single value or a column of values. A row subquery is a subquery variant that returns a single row and
can thus return more than one column value. Legal operators for row subquery comparisons are:
=
>
<
>=
Here are two examples:
SELECT * FROM t1
WHERE (col1,col2) = (SELECT col3, col4 FROM t2 WHERE id = 10);
SELECT * FROM t1
WHERE ROW(col1,col2) = (SELECT col3, col4 FROM t2 WHERE id = 10);
For both queries, if the table
row. If this row has
expression is
WHERE
are not equal the
is rare, but this example shows why it might be useful. To most people, the
SOME
ALL
ALL (subquery)
of the values in the column that the subquery returns." For example:
because
is greater than all three values in t2. The expression is
10
because there is a single value
if table
TRUE
when table
NULL
values and empty tables are "edge cases." When writing
NULL
ALL. Thus, these two statements are the same:
<>
<=
<>
!=
<=>
contains a single row with
t2
and
col3
col4
and each query returns those
TRUE
and
values of any
col1
col2
Subquery Syntax
containing (10). The expression is
t1
contains (0,NULL,1).
t2
is empty. So, the following expression is
t2
is empty:
t2
when table
NULL
t2
id =
values equal to the
col1
t1
row, the expression is
t1
1101
if the comparison is
TRUE
if table
TRUE
FALSE
in table
that is greater than 10.
12
t2
is empty:
10, the subquery returns a single
and
values of any rows in t1, the
col2
rows. If the
row
t2
col3
and the query returns
FALSE
<> SOME
contains
t2
if table
t2
when table
TRUE
t2
and
values
col4

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents