March 12th, 2009

ALL with Subselects

Posted by admin in N. Subselects

A subquery comparison test uses the same six operators (=, <, <=, >, >=, <>) discussed previously.
The subquery can include only one column name or expression.
= ALL is rarely used, since every value returned by the subselect must be identical and equal to the test value.

The ALL operator returns a TRUE value:
> when every row in a subselect matches the value comparison,
> or when no rows in a subselect match the value comparison.
This may seem backward, but if the subselect returns no rows, the ALL condition is TRUE.

The ALL operator returns a FALSE value:
> when some rows in a subselect do not match the value comparison.

The ALL operator returns a NULL value:
> when any rows in a subselect are NULL, then the operation evaluates to NULL (not TRUE or FALSE).

< ALL (subselect) means less than every value in the subselect and is equivalent to < MIN (subselect values).
> ALL (subselect) means greater than every value in the subselect and is equivalent to > MAX (subselect values).

                     Format:           SELECT select_columns
                                              FROM tables
                                            WHERE value operator ALL (subselect);

> DB2, Oracle, Postgre SQL, and SQL Server support ALL.

> MySQL does not support ALL.

Comments are closed.

Sorry, the comment form is closed at this time.