Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql: how to copy from one table into another table

Tags:

sql

sqlite

table A's structure is a subset of table B, that means the table A's all the columns are the first columns of table B, but table B has more columns than table A. My question, what's the SQL statment to copy all the rows from table A to table B(the missing columns in table B will be kept empty).

like image 490
Bin Chen Avatar asked Oct 02 '10 05:10

Bin Chen


1 Answers

Use:

INSERT INTO TABLE_B
SELECT col1,
       col2,
       col3,
       NULL
  FROM TABLE_A

Use NULL as the placeholder for however many columns you can't populate from TABLE_A, assuming TABLE_B columns allow NULL values.

like image 131
OMG Ponies Avatar answered Sep 23 '22 05:09

OMG Ponies