Categories
SQL / MySQL Tips and Tutorials

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.

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.

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

Comments are closed.