Mysql 查询关联临时表查询数据和更新




1、mysql根据另一张表更新

UPDATE table_name1 a JOIN table_name2 b on a.id = b.id set a.desc = b.name;



UPDATE
  fzlx_Instruction f
LEFT JOIN
  (
    select
      d.Drug_Name as drugName,
      d.Global_drug_id
    from
      fzlx_Drug as d
    where
      d.Drug_Name is not null
      and
      d.Global_drug_id is not null
    GROUP BY
      d.Drug_Name,
      d.Global_drug_id
  )
t1
on f.drug_id = t1.Global_drug_id
set f.Drug_Name = t1.drugName;

 

 

 

二、关联查询

mysql查询关联临时表查询数据
括号()的作用,先执行括号里面的命令,提高优先级 将结果重新查询

select * from fzlx_Instruction as f LEFT JOIN ( select d.Drug_Name, d.Global_drug_id from fzlx_Drug as d where d.Drug_Name is not null and d.Global_drug_id is not null GROUP BY d.Drug_Name, d.Global_drug_id ) t1 on f.drug_id = t1.Global_drug_id

 

posted @ 2022-05-18 10:01  林暗惊风  阅读(778)  评论(0)    收藏  举报