Skip to content

Create new table from select query result in MySql

In this post let’s learn how to create a new table in MySql using the output of a select query. You can create a new table from any select query output using the following syntax.

 CREATE TABLE <table-name>
  <select query>;
         

Example

   CREATE TABLE master_data_bkp
  SELECT *
  FROM master;

This query creates a new table called master_data_bkp from the query select * from master

select * from master_data_bkp;

The above query would return data.

This can be done with any select query not just select all.

create table emp_performance 
select round(avg(performance),2) as "AVG PERFORMANCE", 
type as "EMPLOYMENT STATUS", DATE(week) as "WEEK" from emp_performance
group by type, week
order by week desc;

See also  ERROR 1017 (HY000): Can't find file: './....frm' (errno: 13) - MySQL error. How to fix?
SQL

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.