SELECT
Syntax
1083
You are permitted to specify
DUAL
as a dummy table name in situations where no tables are
referenced:
mysql>
SELECT 1 + 1 FROM DUAL;
-> 2
DUAL
is purely for the convenience of people who require that all
SELECT
statements should have
FROM
and possibly other clauses. MySQL may ignore the clauses. MySQL does not require
FROM
DUAL
if no tables are referenced.
In general, clauses used must be given in exactly the order shown in the syntax description. For
example, a
HAVING
clause must come after any
GROUP BY
clause and before any
ORDER BY
clause. The exception is that the
INTO
clause can appear either as shown in the syntax description or
immediately following the
select_expr
list. For more information about
INTO
, see
Section 13.2.8.1,
“
SELECT ... INTO
Syntax”
.
The list of
select_expr
terms comprises the select list that indicates which columns to retrieve.
Terms specify a column or expression or can use
*
-shorthand:
• A select list consisting only of a single unqualified
*
can be used as shorthand to select all columns
from all tables:
SELECT * FROM t1 INNER JOIN t2 ...
•
tbl_name.*
can be used as a qualified shorthand to select all columns from the named table:
SELECT t1.*, t2.* FROM t1 INNER JOIN t2 ...
• Use of an unqualified
*
with other items in the select list may produce a parse error. To avoid this
problem, use a qualified
tbl_name.*
reference
SELECT AVG(score), t1.* FROM t1 ...
The following list provides additional information about other
SELECT
clauses:
• A
select_expr
can be given an alias using
AS alias_name
. The alias is used as the
expression's column name and can be used in
GROUP BY
,
ORDER BY
, or
HAVING
clauses. For
example:
SELECT CONCAT(last_name,', ',first_name) AS full_name
FROM mytable ORDER BY full_name;
The
AS
keyword is optional when aliasing a
select_expr
with an identifier. The preceding example
could have been written like this:
SELECT CONCAT(last_name,', ',first_name) full_name
FROM mytable ORDER BY full_name;
However, because the
AS
is optional, a subtle problem can occur if you forget the comma between
two
select_expr
expressions: MySQL interprets the second as an alias name. For example, in the
following statement,
columnb
is treated as an alias name:
SELECT columna columnb FROM mytable;
For this reason, it is good practice to be in the habit of using
AS
explicitly when specifying column
aliases.
It is not permissible to refer to a column alias in a
WHERE
clause, because the column value might not
yet be determined when the
WHERE
clause is executed. See
Section C.5.5.4, “Problems with Column
Aliases”
.
• The
FROM table_references
clause indicates the table or tables from which to retrieve rows.
If you name more than one table, you are performing a join. For information on join syntax, see
Section 13.2.8.2, “
JOIN
Syntax”
. For each table specified, you can optionally specify an alias.
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...