Copy Data from one table to another table

GI.Joe

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.

Gordon Linoff

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.

edited at
0

Comments

0 comments
Login to comment

Related

Copy Data from one hbase table to another

Copy table data from one database to another

How to copy data from one table to another table in Firebase?

Copy and then insert data from one cell in a table to another cell in that table

MYSQL, copy data from one table to another table with increment in varchar

SQL - copy data from one table coloum to another table coloum

SQL - copy data from one table column to another table column

How to copy data from one table to another new table in MySQL?

How do i copy data from one table to another table?

How to copy data from one table to another table based on criteria

How copy data from one table into another? PHP

copy table data from one db to another with where condition

mysql copy data from one table to another using foreign key

MySQL copy data from one table to another in different fields

SQL Server Copy Random data from one table to another

How to copy data into empty table from another one by UPDATE?

Copy data from one table to another - Ignore duplicates Postgresql

PostgreSQL: How to copy data from one database table to another database

Copy data from one table to another with specific condition

More Efficient Way to Copy Large Data from One Table to Another

Execute query for copy data from one table to another

Copy data from a Pivot table in one worksheet ot another

Update one column of Table A and copy the data from another table which is Table B

PostgreSQL - copy data from one table, database, server to another table, another database, server

SQLite Copy Table Content from one Table to another Table and Update

How to copy data from one table to another and then delete that data in first table using Java?

Append data from one table to another table

Jquery - copy a row from one table to another

Copy a table from one database to another in Postgres