mysql 多表update

-- 方式1
update uc_organization,uc_users 
set uc_organization.org_name=uc_users.nick_name 
where uc_organization.uid=uc_users.uid and (uc_organization.org_name is null  or uc_organization.org_name='')

-- 方式2
update uc_organization inner join uc_users 
on uc_organization.uid = uc_users.uid 
set uc_organization.org_name=uc_users.nick_name 
where uc_organization.org_name is null  or uc_organization.org_name=''


UPDATE aq_users_expan,aq_answer
SET aq_users_expan.`answer_count`=(SELECT COUNT(*) FROM aq_answer WHERE aq_answer.uid=aq_users_expan.`uid`)

猜你喜欢

转载自huangqiqing123.iteye.com/blog/1930158