mysql update inner join错误
问题描述
问题解答
回答1:create table tb1( country int, province int, city int);create table tb2( country int, province int, city int);insert into tb1 (country, province, city) values (1, 2, 5), (1, 3, null);insert into tb2 (country, province, city) values (1, 2, 5), (1, 3, 7);select * from tb1;select * from tb2;update tb1inner join tb2 on tb1.country=tb2.country and tb1.province=tb2.provinceset tb1.city=tb2.citywhere tb1.city is null; -- and tb1.xx=?select * from tb1;select * from tb2;
update from 语句在 mssql 中有效, mysql 似乎无法正常执行
update tb1 set city=r.city from (select country, province, city from tb2) as rwhere tb1.city is null and tb1.country=r.country and tb1.province=r.province
http://sqlfiddle.com/#!9/4df7d7/2
相关文章:
1. mysql - 在不允许改动数据表的情况下,如何优化以varchar格式存储的时间的比较?2. css - chrome下a标签嵌套img 显示会多个小箭头?3. docker网络端口映射,没有方便点的操作方法么?4. javascript - 网页打印页另存为pdf的代码一个问题5. vim - docker中新的ubuntu12.04镜像,运行vi提示,找不到命名.6. css3 - 纯css实现点击特效7. java中返回一个对象,和输出对像的值,意义在哪儿8. javascript - 有适合开发手机端Html5网页小游戏的前端框架吗?9. javascript - Img.complete和img.onload判断图片加载完成有什么区别?10. mysql 为什么主键 id 和 pid 都市索引, id > 10 走索引 time > 10 不走索引?
