
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- 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 put comments in a column of existing MySQL table?
- How can I drop an existing column from a MySQL table?
- How can we modify column/s of MySQL 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?
- How can we remove a column from MySQL table?
- Create MySQL query to create a table from an existing table?
- Adding new enum column to an existing MySQL table?

Advertisements