R
R
Rinat Bakiev2015-03-24 11:02:36
PostgreSQL
Rinat Bakiev, 2015-03-24 11:02:36

How to update a table from another table?

Hello!
There are two tables in different bases. In terms of structure, they are almost the same
database 1
Table Warehouse
Name | Quantity | Note | Column not in database 2
------------------------------------- ----------------
Item1 0 2
Item2 1 2
Item3 3 2
Item4 1 2
database 2
Table Warehouse_archive
Name | Quantity | Note
------------------------------------------------- ----------
Product1 4 2
Product2 2 2
Product3 4 2
Product4 5 2
Number of records: 600 Which name needs to be updated.
From the database 2 database of the Warehouse table with the name field ( Product1, Product3) take the values ​​of the column (Name, quantity) update in database 1 Warehouse_Archive.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
RJDaallen, 2015-03-24
@RJDaallen

as an option, for mysql, look here www.mysql.ru/docs/man/INSERT_SELECT.html
just your option

K
krypt3r, 2015-03-24
@krypt3r

dblink or temporary export of that table

E
exedealer, 2015-04-03
@exedealer

In the receiving database, you can create a foreign table on the table from the source database and then execute the following query in the receiving database.

insert into target_table(col1, col2)
select col1, col2
from source_foreign_table
/* where some condition */

www.postgresql.org/docs/9.3/static/sql-createforei...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question