I have two tables with different number of rows and I wish to copy a column of data and insert it to the second table. How could I do that? I know how to insert the data with two tables with the same number of columns but what I should of in my situation?
TABLE A
ID | Exp | T/F | RATE |
======================
1 | 11 | T | 0.45|
-----------------------
: : :
Table B
ID | Year | Exp | Sex | V | VI | VII|
======================================
1 | 2011 | 11 | M | x | x | c |
--------------------------------------
: : : : : : :
In the example, I wish to insert [Rate] from table A to table B. What can I do? Thank you.
This is an update
operation.
First, though, if the column is not present, you need to add it:
alter table b add rate decimal(4, 2); -- or whatever the appropriate type is
Then you can update it. Assuming the id
columns are the same:
update b
set rate = a.rate
from b join
a
on b.id = a.id;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments