mysql用一個表的數據更新另外一張表

用b表查詢出來的數據更新a表

update  a,  b 
set a.title=b.title, a.name=b.name
where a.id=b.id

用多個表則使用查詢,然後用子查詢代替

update gksite.gk_cmpt as n,
(select a.type as type,a.endTime as end_time,b.cmpt_id as cmpt_id from  raceenroll.competition as a,gksite.gk_cmpt as b,common.neucmpt as c  where a.cmptId=c.gCmptId and  b.cmpt_id=c.gtCmptId  and b.cmpt_status=2) as  m
set n.cmpt_type=m.type , n.end_time=m.end_time,is_day_rank=0 where n.cmpt_id=m.cmpt_id
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章