When you look at the MySQL 5.1 reference manual, you find that MySQL provides a two-table associated update operation. The original text reads as follows:
UPDATE items,monthSET items.price=month.PriceWHERE items.id=month. ID;
Constructs a table in MySQL to verify a bit
Mysql> Select * fromtest;+------+--------+|Id|Salary|+------+--------+| 1 | - || 2 | $ || 3 | - |+------+--------+3Rowsinch Set(0.00sec) MySQL> Select * fromtest1;+------+--------+|Id|Salary|+------+--------+| 1 | - || 2 | - |+------+--------+2Rowsinch Set(0.00sec) MySQL> UpdateTest,test1SetTest.salary=Test1.salarywhereTest.id=test1.id; Query OK,2Rows Affected (0.00sec) Rows matched:2Changed:2Warnings:0MySQL> Select * fromtest;+------+--------+|Id|Salary|+------+--------+| 1 | - || 2 | - || 3 | - |+------+--------+3Rowsinch Set(0.00Sec
It is not difficult to see that the two tables associated with update only updated the row with ID 1 and ID 2 in test.
Think about it, Oracle does not seem to provide two tables associated with the update operation, also entered the above statement, Oracle error, error information as follows:
sql> update test,test1 set test.salary= test1.salary where test.id= test1.id; update test,test1 set Test.salary= test1.salary = Span style= "color: #000000;" >test1.id * 1 line error: ORA - 00971 : Missing set keyword
Later, check the official documents, this syntax is not supported, then how to achieve this effect in Oracle MySQL?
A bit of tinkering, though it came out, was somewhat complicated.
Sql> UpdateTestSetTest.salary=(SelectSalary fromTest1whereTest1.id=test.id)
where exists(Select 1 fromTest1whereTest1.id=test.id); 2 rows have been updated. SQL> Select * fromtest; ID SALARY---------- ---------- 1 - 2 - 3 -
How to implement MySQL's two-table associated update operation in Oracle