从已经创建的表中选择特定的行来创建MySQL表?
要从已创建的表创建表,请使用CREATE TABLE AS SELECT语句。让我们首先创建一个表-
create table DemoTable1318-> (
-> Id int,
-> FirstName varchar(10),
-> LastName varchar(10),
-> Age int
-> );
使用插入命令在表中插入一些记录-
insert into DemoTable1318 values(1,'Chris','Brown',21);insert into DemoTable1318 values(2,'David','Miller',24);
insert into DemoTable1318 values(3,'Carol','Taylor',23);
使用select语句显示表中的所有记录-
select * from DemoTable1318;
输出结果
+------+-----------+----------+------+| Id | FirstName | LastName | Age |
+------+-----------+----------+------+
| 1 | Chris | Brown | 21 |
| 2 | David | Miller | 24 |
| 3 | Carol | Taylor | 23 |
+------+-----------+----------+------+
3 rows in set (0.00 sec)
以下是从已创建的表中选择特定行来创建表的查询-
create table DemoTable1319-> as select *from DemoTable1318
-> where Age IN(21,23);
Records: 2 Duplicates: 0 Warnings: 0
使用select语句显示表中的所有记录-
select * from DemoTable1319;
输出结果
+------+-----------+----------+------+| Id | FirstName | LastName | Age |
+------+-----------+----------+------+
| 1 | Chris | Brown | 21 |
| 3 | Carol | Taylor | 23 |
+------+-----------+----------+------+
2 rows in set (0.00 sec)
以上是 从已经创建的表中选择特定的行来创建MySQL表? 的全部内容, 来源链接: utcz.com/z/331562.html