mysql create table from select statement code example

Example 1: how to create a table structure from another table in mysql

CREATE TABLE new_tbl LIKE orig_tbl;  //(creates an empty table only definition is
                                        same.)

Example 2: mysql select into new table

CREATE TABLE artists_and_works
  SELECT artist.name, COUNT(work.artist_id) AS number_of_works
  FROM artist LEFT JOIN work ON artist.id = work.artist_id
  GROUP BY artist.id;

Example 3: mysql create table from select statement

select * into <NEW_TABLE_NAME> from <OLD_TABLE>;

Tags:

Sql Example