带选择的MYSQL更新

时间:2013-07-19 07:04:21

标签: php mysql

我想更新另一个表值的值,这是我的代码

UPDATE 
ag_personal_information 
SET
ag_personal_information.ag_zone_id = 
  (SELECT ag_officer_service_information.ag_zone_id 
                  FROM ag_officer_service_information) 
WHERE
ag_officer_service_information.ag_zone_id <> ag_personal_information.ag_zone_id

2 个答案:

答案 0 :(得分:1)

试试这个

UPDATE ag_personal_information AS A 
SET ag_personal_information.ag_zone_id = (
            SELECT ag_officer_service_information.ag_zone_id 
            FROM ag_officer_service_information AS B 
            WHERE A.ag_officer_service_information.ag_zone_id <> B.ag_personal_information.ag_zone_id) 

答案 1 :(得分:0)

=放在ag_officer_service_information.ag_zone_idag_personal_information.ag_zone_id

之间
 UPDATE ag_personal_information 
     SET ag_personal_information.ag_zone_id =
    (SELECT ag_officer_service_information.ag_zone_id FROM ag_officer_service_information) 
     WHERE ag_officer_service_information.ag_zone_id = ag_personal_information.ag_zone_id