Update updates across tables, update updates across tables
Sometimes we may need to update data between multiple tables. We can use this statement
UPDATE table1,table2 SET table1.column=table2.column, table1.column1=table2.column1WHERE table1.column3=table2.column3
Update data between two tables
Should I use SQL statements?
Update table1 set count = table2.count from table2 where table2.tid = table1.id
In this way, Table 1 can be updated.
========================================================== ========================================================== =====
This is already the best method.
And the efficiency is very high. This is to directly connect two tables to update data.
Cross-Table update using the update keyword in oracle 10 GB
1. update emp A, emp2 B set B. comm = A. comm where B. empno = A. empno;
2. update emp2 B set B. comm = (select A. comm emp A where A. empno = B. empno group by A. comm );
If no group by is added, an error is returned if a duplicate value exists.
3. Save All IDS as a file or specify the id
Spoll id.txt
Select empno from emp;
Spool off
Write a shell
#! /Bin/sh
Cid = $1
If [-z "$1"]; then
Echo "Usage: $0 id.txt"
Exit 1;
Fi
For id in 'cat id.txt '; do
Echo-e "update emp2 B set B. comm = (select A. comm from emp A where A. empno = '$ id ')
Where B. id = '$ id ';"
Done | sqlplus-s 'user/123456'