SQL: INSERT INTO … SELECT … to generate or combine records from existing ones and insert into an existing table

Update: Here is a more advanced use of INSERT INTO … SELECT … to combine multiple tables into one.

While CREATE TABLE … SELECT … mix and mingle records by column from other tables into a table that’s created on the fly, INSERT INTO … SELECT … insert those generated or combined records into an existing table.

Both approaches bear the same grammatical form and you need only change CREATE TABLE to INSERT INTO if what you are dealing is an existent table.

INSERT INTO mingle1 SELECT table1.col1, table1.col3, table2.col2, table2.col6 FROM table1, table2

Therefore you can update the table created with the previous approach and insert newly generated records simply by using the slightly modified query version above.

4 thoughts on “SQL: INSERT INTO … SELECT … to generate or combine records from existing ones and insert into an existing table”

  1. Pingback: MySQL: INSERT INTO … SELECT … FROM …

Comments are closed.

Scroll to Top