Oracle 5.0 Reference Manual page 1105

Table of Contents

Advertisement

permits a
GROUP BY
• The
clause is applied nearly last, just before items are sent to the client, with no
HAVING
optimization.
(LIMIT
A
clause can refer to any column or alias named in a
HAVING
in outer subqueries, and to aggregate functions. However, the SQL standard requires that
must reference only columns in the
accommodate both standard SQL and the MySQL-specific behavior of being able to refer columns in
the
list, MySQL 5.0.2 and up permit
SELECT
in the
clause, columns in outer subqueries, and to aggregate functions.
GROUP BY
For example, the following statement works in MySQL 5.0.2 but produces an error for earlier
versions:
mysql>
SELECT COUNT(*) FROM t GROUP BY col1 HAVING col1 = 2;
If the
clause refers to a column that is ambiguous, a warning occurs. In the following
HAVING
statement,
is ambiguous because it is used as both an alias and a column name:
col2
SELECT COUNT(col1) AS col2 FROM t GROUP BY col2 HAVING col2 = 2;
Preference is given to standard SQL behavior, so if a
and as an aliased column in the output column list, preference is given to the column in the
BY
column.
GROUP BY
• Do not use
for items that should be in the
HAVING
following:
SELECT
col_name
FROM
Write this instead:
SELECT
col_name
FROM
• The
clause can refer to aggregate functions, which the
HAVING
SELECT user, MAX(salary) FROM users
GROUP BY user HAVING MAX(salary) > 10;
(This did not work in some older versions of MySQL.)
• MySQL permits duplicate column names. That is, there can be more than one
the same name. This is an extension to standard SQL. Because MySQL also permits
to refer to
HAVING
select_expr
SELECT 12 AS a, a FROM t GROUP BY a;
In that statement, both columns have the name a. To ensure that the correct column is used for
grouping, use different names for each select_expr.
• MySQL resolves unqualified column or alias references in
values, then in the columns of the tables in the
select_expr
clauses, it searches the
HAVING
and HAVING, this differs from the pre-MySQL 5.0 behavior that used the same rules as
GROUP BY
for
ORDER
BY.)
• The
clause can be used to constrain the number of rows returned by the
LIMIT
takes one or two numeric arguments, which must both be nonnegative integer constants
LIMIT
(except when using prepared statements).
With two arguments, the first argument specifies the offset of the first row to return, and the second
specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
SELECT
modifier. See
WITH ROLLUP
is applied after HAVING.)
GROUP BY
tbl_name
HAVING
col_name
tbl_name
WHERE
col_name
values, this can result in an ambiguity:
clause before searching in the
FROM
1085
Syntax
Section 12.15.2,
select_expr
clause or columns used in aggregate functions. To
to refer to columns in the
HAVING
column name is used both in
HAVING
clause. For example, do not write the
WHERE
> 0;
> 0;
WHERE
ORDER BY
FROM
"GROUP BY
Modifiers".
in the
SELECT
HAVING
list, columns
SELECT
clause cannot:
select_expr
GROUP BY
clauses by searching in the
clause. For
GROUP BY
values. (For
select_expr
statement.
SELECT
list or
GROUP
with
and
or

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the 5.0 and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Mysql 5.0

Table of Contents