SQL INSERT INTO SELECT Statement
In SQL, the INSERT INTO SELECT Statement is used to insert data into the table directly. The data which is inserted is the result we get from the SELECT statement. This statement is generally used when we want to copy some data from one table to another. There is a thing to remember, the data returned by the SELECT statement must be compatible with other table columns on which we try to insert them. Otherwise, it will throw us an error.
Syntax:
INSERT INTO table_01 (column_01, column_02,…………………)
SELECT (column_01, column_02,…………………)
FROM table_02;
SQL INSERT INTO SELECT Statement
In SQL, the INSERT INTO statement is used to add or insert records to the specified table. We can use this statement to add data directly to the table. We use the VALUES keyword along with the INSERT INTO statement. VALUES keyword is accompanied by column names in a specific order in which we want to insert values in them. SELECT statement is used to retrieve data from the table. We can use a SELECT statement along with a where clause too in order to fetch some specific data from the table.
In this article, we are going to learn how to use the INSERT INTO statement along with the SELECT statement. We will be going through its various examples along with their respective explanations. We will also see how it can be used in real-world situations.