TABLE是MySQL8.0.19中引入的DML语句,它返回命名表的行和列。TABLE is a DML statement introduced in MySQL 8.0.19 which returns rows and columns of the named table.
TABLEtable_name[ORDER BYcolumn_name] [LIMITnumber[OFFSETnumber]]
The TABLE statement in some ways acts like SELECT. TABLE语句在某些方面的作用类似于SELECT。Given the existance of a table named 给定名为t, the following two statements produce identical output:t的表的存在,以下两个语句产生相同的输出:
TABLE t; SELECT * FROM t;
You can order and limit the number of rows produced by 您可以分别使用TABLE using ORDER BY and LIMIT clauses, respectively. ORDER BY和LIMIT子句对TABLE生成的行数进行排序和限制。These function identically to the same clauses when used with 与SELECT (including an optional OFFSET clause with LIMIT), as you can see here:SELECT一起使用时,这些子句的功能与相同的子句相同(包括带LIMIT的可选OFFSET子句),如下所示:
mysql>TABLE t;+----+----+ | a | b | +----+----+ | 1 | 2 | | 6 | 7 | | 9 | 5 | | 10 | -4 | | 11 | -1 | | 13 | 3 | | 14 | 6 | +----+----+ 7 rows in set (0.00 sec) mysql>TABLE t ORDER BY b;+----+----+ | a | b | +----+----+ | 10 | -4 | | 11 | -1 | | 1 | 2 | | 13 | 3 | | 9 | 5 | | 14 | 6 | | 6 | 7 | +----+----+ 7 rows in set (0.00 sec) mysql>TABLE t LIMIT 3;+---+---+ | a | b | +---+---+ | 1 | 2 | | 6 | 7 | | 9 | 5 | +---+---+ 3 rows in set (0.00 sec) mysql>TABLE t ORDER BY b LIMIT 3;+----+----+ | a | b | +----+----+ | 10 | -4 | | 11 | -1 | | 1 | 2 | +----+----+ 3 rows in set (0.00 sec) mysql>TABLE t ORDER BY b LIMIT 3 OFFSET 2;+----+----+ | a | b | +----+----+ | 1 | 2 | | 13 | 3 | | 9 | 5 | +----+----+ 3 rows in set (0.00 sec)
TABLE differs from SELECT in two key respects:TABLE在两个关键方面与SELECT不同:
For limiting which table columns are returned, filtering rows beyond what can be accomplished using 要限制返回的表列,请使用ORDER BY and LIMIT, or both, use SELECT.SELECT筛选超出使用ORDER BY和LIMIT(或两者)可以完成的范围的行。
TABLE can be used with temporary tables.TABLE可以与临时表一起使用。
TABLE can also be used in place of SELECT in a number of other constructs, including those listed here:TABLE还可以在许多其他构造中代替SELECT,包括下面列出的构造:
With 使用UNION, as shown here:UNION,如下所示:
mysql>TABLE t1;+---+----+ | a | b | +---+----+ | 2 | 10 | | 5 | 3 | | 7 | 8 | +---+----+ 3 rows in set (0.00 sec) mysql>TABLE t2;+---+---+ | a | b | +---+---+ | 1 | 2 | | 3 | 4 | | 6 | 7 | +---+---+ 3 rows in set (0.00 sec) mysql>TABLE t1 UNION TABLE t2;+---+----+ | a | b | +---+----+ | 2 | 10 | | 5 | 3 | | 7 | 8 | | 1 | 2 | | 3 | 4 | | 6 | 7 | +---+----+ 6 rows in set (0.00 sec)
The 刚才显示的UNION just shown is equivalent to the following statement:UNION等效于以下语句:
mysql> SELECT * FROM t1 UNION SELECT * FROM t2;
+---+----+
| a | b |
+---+----+
| 2 | 10 |
| 5 | 3 |
| 7 | 8 |
| 1 | 2 |
| 3 | 4 |
| 6 | 7 |
+---+----+
6 rows in set (0.00 sec)
TABLE can also be used together in unions with SELECT statements, VALUES statements, or both. TABLE还可以与SELECT语句、VALUES语句或两者一起在联合中使用。See Section 13.2.10.3, “UNION Clause”.请参阅第13.2.10.3节,“UNION子句”。
With 使用INTO to populate user variables, and with INTO OUTFILE or INTO DUMPFILE to write table data to a file. INTO填充用户变量,使用INTO OUTFILE或INTO DUMPFILE将表数据写入文件。See Section 13.2.10.1, “SELECT ... INTO Statement”, for more specific information and examples.请参阅第13.2.10.1节,“SELECT ... INTO语句以了解更具体的信息和例子。
In many cases where you can employ subqueries. 在许多情况下,您可以使用子查询。Given any table 给定任何一个表t1 with a column named a, and a second table t2 having a single column, statements such as the following are possible:t1有一个名为a的列,第二个表t2有一个单独的列,这样的语句是可能的:
SELECT * FROM t1 WHERE a IN (TABLE t2);
Assuming that the single column of table 假设表ts is named x, the preceding is equivalent to each of the statements shown here (and produces exactly the same result in either case):ts的单列名为x,则前面的语句等价于此处显示的每一条语句(并且在任何一种情况下产生完全相同的结果):
SELECT * FROM t1 WHERE a IN (SELECT x FROM t2); SELECT * FROM t1 WHERE a IN (SELECT * FROM t2);
See Section 13.2.11, “Subqueries”, for more information.请参阅第13.2.11节,“子查询”。
With 使用INSERT and REPLACE statements, where you would otherwise use SELECT *. INSERT和REPLACE语句,否则将使用SELECT *。See Section 13.2.6.1, “INSERT ... SELECT Statement”, for more information and examples.请参阅第13.2.6.1节,“INSERT ... SELECT语句”以了解有关更多信息和示例。
在许多情况下,也可以使用TABLE can also be used in many cases in place of the SELECT in CREATE TABLE ... SELECT or CREATE VIEW ... SELECT. TABLE来代替CREATE TABLE中 ... SELECT或CREATE VIEW ... SELECT中的SELECT。See the descriptions of these statements for more information and examples.有关更多信息和示例,请参见这些语句的描述。