Oracle 5.0 Reference Manual page 1120

Table of Contents

Advertisement

For example:
... WHERE 'a' = (SELECT column1 FROM t1)
MySQL also permits this construct:
non_subquery_operand
At one time the only legal place for a subquery was on the right side of a comparison, and you might
still find some old DBMSs that insist on this.
Here is an example of a common-form subquery comparison that you cannot do with a join. It finds all
the rows in table
SELECT * FROM t1
WHERE column1 = (SELECT MAX(column2) FROM t2);
Here is another example, which again is impossible with a join because it involves aggregating for one
of the tables. It finds all rows in table
SELECT * FROM t1 AS t
WHERE 2 = (SELECT COUNT(*) FROM t1 WHERE t1.id = t.id);
For a comparison of the subquery to a scalar, the subquery must return a scalar. For a comparison of
the subquery to a row constructor, the subquery must be a row subquery that returns a row with the
same number of values as the row constructor. See
13.2.9.3. Subqueries with ANY, IN, or
Syntax:
operand comparison_operator
operand
IN (subquery)
operand comparison_operator
Where
comparison_operator
=
>
<
>=
The
keyword, which must follow a comparison operator, means "return
ANY
for
TRUE
ANY
SELECT s1 FROM t1 WHERE s1 > ANY (SELECT s1 FROM t2);
Suppose that there is a row in table
(21,14,7)
contains (20,10), or if table
t2
contains (NULL,NULL,NULL).
When used with a subquery, the word
same:
SELECT s1 FROM t1 WHERE s1 = ANY (SELECT s1 FROM t2);
SELECT s1 FROM t1 WHERE s1 IN
and
IN
= ANY
cannot. See
= ANY
is not an alias for
NOT IN
The word
SOME
SELECT s1 FROM t1 WHERE s1 <> ANY
LIKE (subquery)
for which the
t1
column1
ANY (subquery)
SOME (subquery)
is one of these operators:
<=
<>
!=
of the values in the column that the subquery returns." For example:
because there is a value
t2
are not synonyms when used with an expression list.
Section 12.3.2, "Comparison Functions and
ANY, but for
<>
is an alias for ANY. Thus, these two statements are the same:
Subquery Syntax
value is equal to a maximum value in table t2:
containing a value that occurs twice in a given column:
t1
Section 13.2.9.5, "Row
SOME
containing (10). The expression is
t1
in
that is less than 10. The expression is
7
t2
is empty. The expression is unknown (that is, NULL) if table
is an alias for
IN
=
(SELECT s1 FROM t2);
ALL. See
Section 13.2.9.4, "Subqueries with
<>
(SELECT s1 FROM t2);
1100
Subqueries".
TRUE
TRUE
ANY. Thus, these two statements are the
can take an expression list, but
IN
Operators".
if the comparison is
if table
contains
t2
if table
FALSE
t2
ALL".

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents