选择进入MySQL?
要在MySQL中进行选择,请使用CREATETABLESELECT命令。语法如下-
CREATE TABLE yourTableName SELECT *FROM yourOriginalTableName;
要了解,让我们首先创建一个表-
mysql> create table SelectIntoDemo -> ( -> Id int, -> Name varchar(200) -> );
让我们借助insert命令将一些记录插入表中。查询如下-
mysql> insert into SelectIntoDemo values(1,'Bob'),(2,'Carol'),(3,'David'); Records: 3 Duplicates: 0 Warnings: 0
在select语句的帮助下显示所有记录。查询如下-
mysql> select *from SelectIntoDemo;
这是输出-
+------+-------+ | Id | Name | +------+-------+ | 1 | Bob | | 2 | Carol | | 3 | David | +------+-------+ 3 rows in set (0.00 sec)
现在,您可以应用开头讨论的上述语法。查询如下-
mysql> create table yourTempTable select *from SelectIntoDemo; Records: 3 Duplicates: 0 Warnings: 0
检查所有具有新表名“yourTempTable”的记录。查询如下-
mysql> select *from yourTempTable;
以下是输出-
+------+-------+ | Id | Name | +------+-------+ | 1 | Bob | | 2 | Carol | | 3 | David | +------+-------+ 3 rows in set (0.00 sec)