Article Information
This SQL Tutorial contains and tries to cover following subjects:
- Explanation of Inserting a SELECT result set into table in sql.
- Example to Inserting data from a SELECT result set into table in sql
Articles tries to provide answer to following questions
- How to insert a result of SELECT into table
- How to insert multiple rows in a single INSERT in sql?
- How to use sql insert select query in sql?
Article covers followings indirectly:
- INSERT command
- sql insert
Articles pre-requisites following information:
- General knowledge of SQL Server Management Studio
- General knowledge of INSERT command
Inserting multiple rows in same INSERT command in SQL
Sql INSERT is not only limited to inserting given values. To recall, we had covered INSERT basic form and inserting multiple rows in same INSERT statement. To extend INSERTs, in this article we will look into inserting data from a SELECT result set in INSERT. When we use SELECT query, we get a result set. Columns and rows as a table. Lets assume that we want to insert that table, partially a column or more its columns into another table with SELECT. Insert command works with SELECT to achieve that kind of tasks. To be more specific, we can insert rows from a SELECT result in same query.
Lets recall basic sql INSERT syntax again:
INSERT (column1, column2) VALUES (value1, values2)
To insert data from a SELECT, syntax will be as follows:
INSERT (column1, column2) SELECT statement
Lets see sql insert which gets data from a SELECT in a sql example as practice
As above sql insert example indicates, new row has been inserted into the table. We provided two column name, and values come from SELECT statement. The select statement could be a select from a table to insert entire table in sql insert. Moreover, we could add WHERE or another filters to get data from another table and insert it to another.