mysql select into new table code example
Example 1: mysql select into new table
-- Insert into existing my_table
INSERT INTO my_table my SELECT * FROM another_table an WHERE an.col1 > 10;
-- or directely create the new table
CREATE TABLE my_table AS SELECT * FROM another_table an WHERE an.col1 > 10;
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: how to create a table based on another table in mysql
Press CTRL+C to copy CREATE TABLE new_tbl [AS] SELECT * FROM orig_tbl;
Example 4: mysql create table from select statement
select * into <NEW_TABLE_NAME> from <OLD_TABLE>;