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>;


   CREATE TABLE master_data_bkp
  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  Update random values from a list into a column in MySQL

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.