Home > Database > Mysql Tutorial > body text

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

王林
Release: 2023-08-25 08:33:09
forward
1086 people have browsed it

我们如何通过从另一个现有表中选择特定列来创建新的 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template