Rechercher dans le manuel MySQL
13.2.12 TABLE Statement
TABLE
is a DML statement introduced
in MySQL 8.0.19 which returns rows and columns of the named table.
The TABLE
statement in some ways
acts like SELECT
. Given the
existance of a table named t
, the following two
statements produce identical output:
You can order and limit the number of rows produced by
TABLE
using ORDER
BY
and LIMIT
clauses, respectively.
These function identically to the same clauses when used with
SELECT
(including an optional
OFFSET
clause with LIMIT
),
as you can see here:
+----+----+ | a | b | +----+----+ | 1 | 2 | | 6 | 7 | | 9 | 5 | | 10 | -4 | | 11 | -1 | | 13 | 3 | | 14 | 6 | +----+----+ +----+----+ | a | b | +----+----+ | 10 | -4 | | 11 | -1 | | 1 | 2 | | 13 | 3 | | 9 | 5 | | 14 | 6 | | 6 | 7 | +----+----+ +---+---+ | a | b | +---+---+ | 1 | 2 | | 6 | 7 | | 9 | 5 | +---+---+ +----+----+ | a | b | +----+----+ | 10 | -4 | | 11 | -1 | | 1 | 2 | +----+----+ +----+----+ | a | b | +----+----+ | 1 | 2 | | 13 | 3 | | 9 | 5 | +----+----+
TABLE
differs from
SELECT
in two key respects:
For limiting which table columns are returned, filtering rows
beyond what can be accomplished using ORDER BY
and LIMIT
, or both, use
SELECT
.
TABLE
can be used with temporary
tables.
TABLE
can also be used in place of
SELECT
in a number of other
constructs, including those listed here:
With
UNION
, as shown here:- +---+----+
- | a | b |
- +---+----+
- | 2 | 10 |
- | 5 | 3 |
- | 7 | 8 |
- +---+----+
- +---+---+
- | a | b |
- +---+---+
- | 1 | 2 |
- | 3 | 4 |
- | 6 | 7 |
- +---+---+
- +---+----+
- | a | b |
- +---+----+
- | 2 | 10 |
- | 5 | 3 |
- | 7 | 8 |
- | 1 | 2 |
- | 3 | 4 |
- | 6 | 7 |
- +---+----+
The
UNION
just shown is equivalent to the following statement:- +---+----+
- | a | b |
- +---+----+
- | 2 | 10 |
- | 5 | 3 |
- | 7 | 8 |
- | 1 | 2 |
- | 3 | 4 |
- | 6 | 7 |
- +---+----+
TABLE
can also be used together in unions withSELECT
statements,VALUES
statements, or both. See Section 13.2.10.3, “UNION Clause”.With
INTO
to populate user variables, and withINTO OUTFILE
orINTO DUMPFILE
to write table data to a file. See Section 13.2.10.1, “SELECT ... INTO Statement”, for more specific information and examples.In many cases where you can employ subqueries. Given any table
t1
with a column nameda
, and a second tablet2
having a single column, statements such as the following are possible:Assuming that the single column of table
ts
is namedx
, the preceding is equivalent to each of the statements shown here (and produces exactly the same result in either case):See Section 13.2.11, “Subqueries”, for more information.
With
INSERT
andREPLACE
statements, where you would otherwise useSELECT *
. See Section 13.2.6.1, “INSERT ... SELECT Statement”, for more information and examples.TABLE
can also be used in many cases in place of theSELECT
inCREATE TABLE ... SELECT
orCREATE VIEW ... SELECT
. See the descriptions of these statements for more information and examples.
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-table.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.