Geeks With Blogs
Nouman Zakir while (true) { Post.NewArticle(); }
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.

Posted on Tuesday, August 4, 2009 4:57 AM SQL | Back to top


Comments on this post: Using SELECT statement to INSERT records in SQL

# re: Using SELECT statement to INSERT records in SQL
Requesting Gravatar...
This is very useful, as a beginner SQL I could never get select into's to work properly.
Left by used macbooks on Aug 04, 2009 5:56 AM

# re: Using SELECT statement to INSERT records in SQL
Requesting Gravatar...
is it nessesary table_A that the Column names are in order, or we can
Left by Sharif on Dec 15, 2010 4:02 AM

# re: Using SELECT statement to INSERT records in SQL
Requesting Gravatar...
Well this does looks even more complicated than what I have done so far. From the looks of things, I would advise to seek the help of a professional before doing something like this on your own and risk it all.

hotel catalina island
Left by Kelvin on Dec 30, 2015 1:40 PM

# re: Using SELECT statement to INSERT records in SQL
Requesting Gravatar...
Well this does looks even more complicated than what I have done so far. From the looks of things, I would advise to seek the help of a professional before doing something like this on your own and risk it all.

hotel catalina island
Left by Kelvin on Dec 30, 2015 1:41 PM

# re: Using SELECT statement to INSERT records in SQL
Requesting Gravatar...
I am a beginner in all this things dealing with SQL and so I found this article really helpful and thanks for the same. I do understand almost everything discussed here but I don’t have the confidence to do all this things and thanks a lot!
outsource medical billing
Left by Merlin John on Jun 07, 2016 5:56 PM

Your comment:
 (will show your gravatar)


Copyright © Nouman Zakir | Powered by: GeeksWithBlogs.net