
- 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 use WHERE condition when creating a table with CTAS (Create Table as Selected) script?
As we know that we can copy the data and structure from an existing table by CTAS script. Use of WHERE clause is demonstrated in the example below
mysql> Create table EMP_BACKUP2 AS SELECT * from EMPLOYEE WHERE id = 300 AND Name = 'Mohan'; Query OK, 1 row affected (0.14 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql> Select * from EMP_BACKUP2; +------+-------+ | Id | Name | +------+-------+ | 300 | Mohan | +------+-------+ 1 row in set (0.00 sec)
In the example above, we have created a table named EMP_BACKUP1 from table ‘Employee’ with some conditions. MySQL creates the table with only one row based on those conditions.
- Related Articles
- What is the concept of CTAS (CREATE TABLE AS SELECTED) in MySQL?
- Can we use “When” as column name in CREATE TABLE statement?
- Can we use {} while creating a MySQL table?
- How can we create a MySQL table by using PHP script?
- How can we create a MySQL temporary table by using PHP script?
- Will “create table table” work in MySQL since we cannot use reserved words as table name?
- How can we copy data with some condition/s from existing MySQL table?
- Can we use “year” as a column came in a MySQL Table?
- How can we use MySQL EXPORT_SET() function with column of a table?
- How can we have multiple virtuals GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- How can we create a table from an existing MySQL table in the database?
- How can we delete an existing MySQL table by using PHP script?
- Can we create a table with a space in name in MySQL?
- How can we display all the records from MySQL table with the help of PHP script?
- Error occurs when table name “references” is set while creating a table

Advertisements