Update updates across tables, update updates across tables

Source: Internet
Author: User

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'

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.