CreatetableEMP_BACKUP1ASSelectnamefromemployee;QueryOK,3rowsaffected(0.25sec)Records:3Duplicates:0Warnings:0mysql"/> CreatetableEMP_BACKUP1ASSelectnamefromemployee;QueryOK,3rowsaffected(0.25sec)Records:3Duplicates:0Warnings:0mysql">

Home  >  Article  >  Database  >  How can we create a new MySQL table by selecting specific columns from another existing table?

How can we create a new MySQL table by selecting specific columns from another existing table?

王林
王林forward
2023-08-25 08:33:091069browse

我们如何通过从另一个现有表中选择特定列来创建新的 MySQL 表?

As we all know, we can copy data and structures from existing tables through CTAS scripts. If we want to select some specific columns from another table then we need to mention them after SELECT. Consider the following example where we create a table named EMP_BACKUP1 by selecting a specific column "name" from the existing table "Employee" -

mysql> Create table EMP_BACKUP1 AS Select name from employee;
Query OK, 3 rows affected (0.25 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> Select * from EMP_BACKUP1;
+--------+
| name   |
+--------+
| Ram    |
| Gaurav |
| Mohan  |
+--------+
3 rows in set (0.00 sec)

We can observe that it copies only the "Employee" table name" column data and structure.

The above is the detailed content of How can we create a new MySQL table by selecting specific columns from another existing table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete