在使用update语句的时候我们有时候需要利用left join 关联表,以下是正确操作:
效果,让指定的order表id为1,2,3数据的finish_at字段更新为freports表的created_at字段
UPDATE ordersLEFT JOIN freportsON freports.order_id = orders.idset orders.finish_at = freports.created_atwhere orders.id in(1,2,3)
UPDATE table_1 t1 left join table_2 t2 on t2.id = t1.tid SET t1.username = t2.uname where t1.id>5;
正常的写法是 update table set field ='' where id=(select ***************条件);
例如:
update tb_wd_rpmtplan_base r set r.SHD_RPMT_DATE='2018-03-11' ,r.id='dfasdf'
where r.PROJECT_ID=(
select p.id from tb_zc_project_info p
join tb_wd_loanapply_base lb on lb.project_id=p.id
where lb.APPLY_NUM='RY201803111340200'
);
但是需要join on的语法我尝试很久,都是写不对的,如果我们一定要用到 left join 更新,那么怎么写呢。我总是在网上看到例子了。
语法是:
update table t1 (left) join table2 t2 on ( t1.id=t2.pid )set ti.fiele='' where t2.filed=''
例如:
UPDATE tb_wd_rpmtplan_base r
LEFT JOIN tb_zc_project_info p
ON r.PROJECT_ID=r.ID
set r.SHD_RPMT_DATE='2018-03-11'
where p.id='dfsadf'
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛