Wondering how to insert into table from SELECT query in SQL? You came to the right place!
A vanilla way of inserting data into a table is different than insert into table from SELECT statement. Here’s why.
The Basics of SELECT in SQL
Many developers that insert data into a table use the INSERT
statement available in SQL. In their basic form, INSERT
statements look like this (MySQL example):
INSERT INTO `table_name` (`column`, `column2`, …) VALUES ("Demo", "Demo", ...);
The structure of this INSERT
statement is as follows:
- First, we specify the statement itself (
INSERT INTO
) - Once the statement is specified, we specify the table that we want to insert data into (
table_name
) - After the table name, we specify columns that we want to insert data into (if we are inserting data into all of the columns that exist within a table, we can skip this step)
- Finally, with the
VALUES
clause we insert specific values (records, rows)
This INSERT
statement will insert specified data into two or more columns.
How to Insert Into Table From SELECT Statement?
To insert into table from SELECT
statement, you need to utilize the INSERT INTO
SQL statement like so:
INSERT INTO `table_name` (`col1`, `col2`) SELECT `col1`, `col2` FROM `demo_table`;
The core idea of the INSERT INTO table from SELECT
statement is that you specify the table name that you want to insert your data into, then specify the columns you want to work with, and then specify the SELECT
SQL statement just like you would specify it in an ordinary way, just don’t forget to with the columns that you specified after the INSERT
statement.
Summary
To insert data into a table from a SELECT
statement, define the INSERT INTO
statement, the table name, column titles, then define a SELECT
statement.
FAQ
How to Insert Into Table From SELECT Statement?
To insert into table from SELECT
statement, specify an INSERT INTO
statement, specify the columns you want to insert the data into, then specify the SELECT
statement.
Why Should I Use a Data Breach Search Engine?
Data breach search engines like BreachDirectory.com will help you see if your data has been stolen in any data breach and also help you perform a wide variety of investigative activities on email addresses, usernames, Blockchain or IP addresses, or other data.

The BreachDirectory API will let you in on the stolen data in the data breach search engine through a JSON form.