

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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.
- Related Questions & Answers
- Create a MySQL table from already created table selecting specific rows?
- How can we create a table from an existing MySQL table in the database?
- Can we add a column to a table from another table in MySQL?
- How can we create a MySQL view by selecting some range of values from a base table?
- How can we create MySQL view by selecting data based on pattern matching from base table?
- How can we copy data with some condition/s from existing MySQL table?
- How can we modify column/s of MySQL table?
- How can we remove a column from MySQL table?
- How can I drop an existing column from a MySQL table?
- How can we put comments in a column of existing MySQL table?
- Create MySQL query to create a table from an existing table?
- How can we remove NOT NULL constraint from a column of an existing MySQL table?
- How can we remove PRIMARY KEY constraint from a column of an existing MySQL table?
- How can we remove FOREIGN KEY constraint from a column of an existing MySQL table?
- Adding new enum column to an existing MySQL table?
Advertisements