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!