mysql 更新数据来自查询怎么处理?
- 工作小总结
- 时间:2018-10-20 17:35
- 2457人已阅读
简介
在工作中,有时候我们更新一个表数据的时候,需要更新的数据来自其他查询出来的结果,这个时候sql怎么写?如下:将tb_option表中name 和valued的值进行互换updatetb_optioninnerjoin(SELECT*fromtb_optionwherequestion_idin(selectidfromtb_questionwhere catagory_id=7
🔔🔔好消息!好消息!🔔🔔
如果您需要注册ChatGPT,想要升级ChatGPT4。凯哥可以代注册ChatGPT账号,代升级ChatGPT4
有需要的朋友👉:微信号
在工作中,有时候我们更新一个表数据的时候,需要更新的数据来自其他查询出来的结果,这个时候sql怎么写?
如下:
将tb_option表中name 和valued的值进行互换
update tb_option inner join (SELECT * from tb_option where question_id in (
select id from tb_question where catagory_id =7 and is_delete = 1) )c
on tb_option.id = c.id set tb_option.name = c.valued,tb_option.valued=c.name