How to update different data before two tables? There must be different data conditions for multiple fields in multiple data entries. The following is an example:
1. Create a table
- Create TableTb1
- (ID varchar2 (10 ),
- XM varchar2 (10 ),
- XB varchar2 (10 ));
-
- Create TableTb2
- (ID varchar2 (10 ),
- XM varchar2 (10 ),
- XB varchar2 (10 ));
2. Insert Test Data
-
- Insert IntoTb1Values('1','Xx','Xx');
-
- Insert IntoTb1Values('2','Yy','Yy');
- Insert IntoTb1Values('3','Zz','Zz');
-
- Insert IntoTb1Values('5','Mm','Mm');
-
-
- Insert IntoTb2Values('1','1','1');
-
- Insert IntoTb2Values('2','2','2');
-
- Insert IntoTb2Values('3','3','3');
- Insert IntoTb2Values('4','4','4');
3. The following two methods are provided to execute the following SQL statement and view the result:
- Update Tb2 Set XM = ( Select XM From Tb1 Where Tb1.id = tb2.id), XB = ( Select XB From Tb1 Where Tb1.id = tb2.id) WhereIDIn(SelectIDFromTb1 );
-
-
- Update tb2 set (XM, XB) = ( select XM, XB from tb1 where tb1.id = tb2.id) where id in ( select id from tb1);
4. Pay attention to the aboveRedAfter removing the labeled SQL statement, perform the test. What is the difference.
5. After the test, delete the table. Develop good habits.
- Drop TableTb1;
- Drop TableTb2;