1

我有一个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)
4

2 回答 2

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
于 2013-01-09T17:18:09.460 回答
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'

**注:未经测试。

于 2013-01-09T17:19:52.590 回答