更新...选择自

时间:2013-01-09 17:09:04

标签: mysql select

我有一个members_info表,里面有很多成员,但我需要做的是用成员A的信息更新成员B的信息。

以下是成员用户ID:

会员A = 98089(member_info_id
成员B = 236505(member_info_id

这两个成员没有任何共同点,所以我不能加入。如何更新会员B的信息?

这是表的结构,但我怀疑它是否有用

mysql> describe member_info;
+-------------------------------+--------------+------+-----+-------------------+----------------+
| Field                         | Type         | Null | Key | Default           | Extra          |
+-------------------------------+--------------+------+-----+-------------------+----------------+
| member_info_id                | int(11)      | NO   | PRI | NULL              | auto_increment |
| member_id                     | int(11)      | NO   | UNI | 0                 |                |
| street                        | varchar(100) | NO   |     | NULL              |                |
| street2                       | varchar(50)  | NO   |     |                   |                |
| city                          | varchar(50)  | NO   |     |                   |                |
| state                         | varchar(50)  | NO   |     |                   |                |
| country_id                    | int(11)      | NO   |     | 0                 |                |
| postal                        | varchar(20)  | NO   |     |                   |                |
| phone                         | varchar(20)  | NO   |     |                   |                |
| street_ntv                    | varchar(100) | NO   |     |                   |                |
| street2_ntv                   | varchar(50)  | NO   |     |                   |                |
| city_ntv                      | varchar(50)  | NO   |     |                   |                |
| state_ntv                     | varchar(50)  | NO   |     |                   |                |
| card_ship_addr                | varchar(250) | NO   |     | NULL              |                |
| tax_id                        | varchar(20)  | NO   |     |                   |                |
| c_type                        | varchar(20)  | NO   |     |                   |                |
| c_number                      | varchar(20)  | NO   |     |                   |                |
| c_code                        | varchar(5)   | NO   |     |                   |                |
| c_date                        | varchar(10)  | NO   |     |                   |                |
| c_name                        | varchar(50)  | NO   |     |                   |                |
| street_b                      | varchar(100) | NO   |     | NULL              |                |
| street_b2                     | varchar(50)  | NO   |     |                   |                |
| city_b                        | varchar(50)  | NO   |     |                   |                |
| state_b                       | varchar(50)  | NO   |     |                   |                |
| country_b_id                  | int(11)      | NO   |     | 0                 |                |
| postal_b                      | varchar(20)  | NO   |     |                   |                |
| new_data                      | text         | NO   |     | NULL              |                |
| new_data_code                 | varchar(10)  | NO   |     |                   |                |
| new_data_date                 | int(11)      | NO   |     | 0                 |                |
| picture_id                    | int(1)       | NO   |     | 0                 |                |
| gender                        | tinyint(4)   | NO   |     | 0                 |                |
| date_birth                    | date         | YES  |     | NULL              |                |
| education                     | tinyint(4)   | NO   |     | 0                 |                |
| income_range                  | tinyint(4)   | NO   |     | 0                 |                |
| li_first_name                 | varchar(200) | NO   |     |                   |                |
| li_last_name                  | varchar(200) | NO   |     |                   |                |
| li_street                     | varchar(200) | NO   |     |                   |                |
| li_street2                    | varchar(200) | NO   |     |                   |                |
| li_city                       | varchar(200) | NO   |     |                   |                |
| li_state                      | varchar(200) | NO   |     |                   |                |
| li_country_id                 | varchar(200) | NO   |     |                   |                |
| li_postal                     | varchar(200) | NO   |     |                   |                |
| li_phone                      | varchar(200) | NO   |     |                   |                |
| li_governmentid               | varchar(200) | NO   |     |                   |                |
| li_gov_filename               | varchar(50)  | NO   |     |                   |                |
| li_gov_id_number              | varchar(30)  | NO   |     |                   |                |
| li_gov_driver_state           | varchar(10)  | NO   |     |                   |                |
| li_gov_country                | varchar(50)  | NO   |     |                   |                |
| li_gov_expdate                | varchar(50)  | NO   |     |                   |                |
| li_governmentdate             | int(11)      | NO   |     | 0                 |                |
| li_staff_id                   | int(11)      | NO   |     | 0                 |                |
| li_verify_date                | int(11)      | NO   |     | 0                 |                |
| private_key                   | varchar(100) | NO   |     |                   |                |
| private_key_enable            | int(11)      | NO   |     | 0                 |                |
| show_displayname              | tinyint(1)   | YES  |     | 0                 |                |
| legal_status                  | int(11)      | NO   | MUL | NULL              |                |
| legal_change_reason           | text         | NO   |     | NULL              |                |
| legal_update_time             | timestamp    | NO   | MUL | CURRENT_TIMESTAMP |                |
| legal_expire_date             | date         | NO   |     | 0000-00-00        |                |
| legal_wf_update_id            | int(11)      | YES  | MUL | NULL              |                |
| legal_gov_update_id           | int(11)      | YES  | MUL | NULL              |                |
| legal_info_update_id          | int(11)      | YES  | MUL | NULL              |                |
| legal_verifications_update_id | int(11)      | YES  | MUL | NULL              |                |
| ewallet_log_update_id         | int(11)      | YES  | MUL | NULL              |                |
| legal_lang                    | tinyint(4)   | YES  | MUL | NULL              |                |
+-------------------------------+--------------+------+-----+-------------------+----------------+
65 rows in set (0.00 sec)

2 个答案:

答案 0 :(得分:4)

即使它们没有直接关联,您仍然可以执行JOIN

UPDATE 
    members_info mb JOIN
    members_info ma ON ma.member_info_id = 98089
SET
    mb.Name = ma.Name,
    mb.Info = ma.Info
    -- Etc... 
WHERE
    mb.member_info_id = 236505

答案 1 :(得分:0)

如果您只想用A的信息更新单个成员(B),那么......

UPDATE members_info member_B, (SELECT DISTINCT ID, Column_1, Column_2, Column_X
                             FROM members_info
                             WHERE id = '98089') member_A

SET member_B.Column_1 = member_A.Column_1, member_B.Column_2 = member_A.Column_2
WHERE member_B.id = '236505'

**注意:未经测试。