- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we create a new MySQL table by selecting specific column/s from another existing table?
As we know that we can copy the data and structure from an existing table by CTAS script. If we want to select some specific column/s from another table then we need to mention them after SELECT. Consider the following example in which we have created a table named EMP_BACKUP1 by selecting a specific column ‘name’ from already 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 copied only the data and structure of ‘name’ column from the ‘Employee’ table.
Advertisements