找回密码
 注册

便捷登录,只需一步

微信登录,快人一步

搜索
查看: 1521|回复: 0

mysql update不能直接使用select的结果

[复制链接]

1992

主题

6万

回帖

18万

积分

管理员

wfits币
2259 个
注册时间
2006-5-15
UID
6502
 楼主| 发表于 2020-3-18 22:44 | 显示全部楼层 |阅读模式
在sql server中,我们可是使用以下update语句对表进行更新:
update a set a.xx= (select yy from b) ;
但是在mysql中,不能直接使用set select的结果,必须使用inner join:
update a inner join (select yy from b) c set a.xx = c.yy


例:
update mb_tariff a inner join   
mb_tariff_temp b  set a.payment =  b.payment
where a.mybus_id = b.mybus_id
and a.tariff_id = b.tariff_id


自行示例:
UPDATE USER INNER JOIN (SELECT id,account FROM USER) c SET user.phone=c.account WHERE user.id = c.id
潍坊社区网旗下潍坊论坛、潍坊人才库,服务潍坊网友!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册 |

本版积分规则

Archiver|手机版|小黑屋|投诉举报|客服微信号:ppm0536|今潍网-潍坊论坛 ( 鲁ICP备14032312号 )

GMT+8, 2025-2-23 05:26 , Processed in 0.087573 second(s), 24 queries , Gzip On.

快速回复 返回顶部 返回列表