Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need SQL help - How can I select rows to perform an insert?

I tried to make the title as clear as possible... here is my scenario:

I have 2 tables (let's call them table A and table B) that have a similar schema. I would like write a stored procedure that would select specific columns of data out of table A, and insert this data as a new record in table B.

Can someone point me in the write direction to make such a query? I am unsure how to "Hold" the values from the first query, so that I may then perform the insert.

I am trying to avoid making a query, processing it with C# and then making another query...

Thanks.

like image 754
mmattax Avatar asked Nov 18 '25 22:11

mmattax


1 Answers

INSERT INTO B (Col1, Col2) SELECT Col1, Col2 FROM A

Is this what you mean?

like image 196
Keith Walton Avatar answered Nov 21 '25 12:11

Keith Walton