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 @   林暗惊风  阅读(763)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示