UPDATE statement: UPDATE the fields in one table to the statement bitsCN.com in another table.
UPDATE statement: The statement used to UPDATE fields in one table to fields in another table.
In a modification to the score query system, a table is changed and a field is added to a table. now, you need to copy the corresponding ID of another table, because such SQL operations are not often used, I even thought of writing a loop to process them. However, I thought that SQL should be able to implement such a function. I checked the manual and it was really simple. there was a syntax for updating... from. Example:
Table
Id subject_id
1 null
2 null
3 null
4 null
5 null
6 null
Table B
Sb_id st_id
5 1
2 2
5 3
5 4
2 5
2 6
The SQL statement is as follows:
1
UPDATEASETA. subject_id = B. sb_idFROMBWHEREB.student_id = A. id
Update: the preceding statement is only applicable to mssql server and the following statement should be used in mysql:
1
UPDATEA, BSETA. subject_id = B. sb_idWHEREB.student_id = A. id
Example 2:
MYSQL is
Update table2 B, (select B. area_id as arid, sum (a. user_amount) as bcount
From table1 a, table2 B
Where a. user_area = B. area_id
Group by arid) c
Set B. count = c. bcount
Where B. area_id = c. arid;
I also installed a MYSQL test and the test passed.
BitsCN.com