MySQL根據表1欄位更新表2欄位
表1:desc table1;
+--------------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------------+------+-----+---------+-------+
| srv_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| trans_name | varchar(40) | NO | | NULL | |
+--------------+---------------------+------+-----+---------+-------+
表2:desc table2;
Field | Type | Null | Key | Default | Extra |
+-----------------+------------------+------+-----+---------+----------------+
| srv_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(40) | NO | | NULL | |
現在要將table2的name欄位更新為table1的trans_name欄位:update table1 a,table2 b set b.name=a.trans_name where a.srv_id=b.srv_id;