You can use the result of a query to create a new table by putting a SELECT statement inside the CREATE TABLE command.
The following example creates a table that contains a subset of the customer_contacts table for one customer. This is also created as a temporary table, so it will be destroyed when you end your MySQL sessions.
mysql> CREATE TEMPORARY TABLE scicorp_customers AS -> SELECT * FROM customer_contacts -> WHERE customer_code ='SCICORP'; Query OK, 4 rows affected (0.01 sec) Records: 4 Duplicates: 0 Warnings: 0
The keyword AS is optional but can be included to make the command more readable. If you view the structure of the new table, you will see that all the columns from customer_contacts are present. ...