Home / code / sql

Insert into a new table

With this you can make a new table based on the selected records.

SELECT fields INTO newtable [IN externdatabase] FROM source

Part Explanation
field1, field2 The names of the fields that must be copied to the new table.
newtable The name of the table that should be made. The name must comply to the rules, it cannot have the same name as any other table.
externdatabase The path to another database
source The name of the existing table from where the records are selected. 1 table, more tables or query.

If you want to add to an already existing table, Use INSERT INTO ... SELECT to add records to a table.

INSERT INTO table (id,name) SELECT id,name FROM table2 WHERE name LIKE 'a%'

 

TOP

Latest script:

 

Books: