Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert into with a sub select * not working

If Table A and B have identical structures (except ID field). In A its autoassigned, but in B it is expecting the value from an insert.

How can I do a INSERT INTO A (select * from B).

What is the quickest, most flexible SQL that can run in a stored proc.

like image 414
JL. Avatar asked Jan 21 '23 22:01

JL.


1 Answers

Specify the columns explicitly:

INSERT INTO TableA (col1, col2)
SELECT col1, col2 FROM TableB
like image 153
Mark Byers Avatar answered Jan 29 '23 13:01

Mark Byers