In INSERT statement, by replacing the VALUES clause with a SELECT statement
you can get a set of records for INSERT.
Suppose I have a table called table_A and I want to populate it with the ID, Name and
Address of table_B. The statement would look something like this:
INSERT table_A (col_id, col_name, col_address)
SELECT col_id, col_name, col_address
FROM table_B
WHERE col_city = 'karachi'
This will take the records with col_city='karachi' and load them into the
table table_A. I can use any type of SELECT statement here.
It just has to return a record set that matches the columns in the
INSERT statement. The number of columns and their data types must match
(or be implicitly convertible). I can also execute a stored procedure
that returns a record set using the EXEC command in place of the SELECT
statement.