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 subselects. 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.
Traduction non disponible
Le manuel MySQL n'est pas encore traduit en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Document créé le 26/06/2006, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/mysql-rf-table.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.