mysql create table from select statement 1

mysql create table from select statement

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

Here is what the above code is Doing:
1. Create a new table called my_table with the same columns as another_table.
2. Insert all the rows from another_table where the value of col1 is greater than 10.
3. Create a new table called my_table with the same columns as another_table.
4. Insert all the rows from another_table where the value of col1 is greater than 10.

Similar Posts