从A表选出数据更新A表是不允许的,需要借助中间临时表操作
联合两个表查询做更新
原创内容如转载请注明:来自 阿权的书房
update table_A set department_id=1425
where user_id IN(
select id from (
select user_id as id from table_B
left join table_A using(m_id)
where l_id=143969
) as tmp
)
where user_id IN(
select id from (
select user_id as id from table_B
left join table_A using(m_id)
where l_id=143969
) as tmp
)
联合两个表查询做更新
UPDATE table_A t1 , (
select d_id,count(*) as cnt from table_B
where h_id = 143969
group by d_id
) t2
SET t1.d_cnt = t2.cnt
WHERE t1.d_id = t2.d_id;
select d_id,count(*) as cnt from table_B
where h_id = 143969
group by d_id
) t2
SET t1.d_cnt = t2.cnt
WHERE t1.d_id = t2.d_id;
原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘