SQL Insert Into Select Statement Example

What is the SQL INSERT INTO SELECT Statement and how it can be used with the database?

The SQL INSERT INTO SELECT statemet is used to insert new data in to the database using SELECT Statement. 

SQL INSERT INTO SELECT Statement Example: 

Assume that you have a table 'customer' in your database.

 

idnameaddressemailphone
1 Jwalant 123 xyz street jwalanttest@test.com 123-456-7890
2 Piyush 456 abc street piyushtest@test.com 123-456-7890
3 Hiren 789 pqr street hirentest@test.com 123-456-7890

You just want to add new customer to the database in another table 'customer2' from customer. You have following columns on the table: name, email, phone. Use following syntax of sql insert into select statement for that case:

          INSERT INTO customers2 (name, address, email, phone) 
          SELECT name, address, email, phone FROM customers;