数据库
首页 > 数据库> > mysql-update多表关联更新实战

mysql-update多表关联更新实战

作者:互联网

    update
    A sp -- 主表
    left join B cc on cc.id = sp.customer_commodity_id -- 替他表
    left join C c on c.commodity_code = cc.commodity_code and c.status=3
    left join D cp on cp.commodity_id = c.id and cp.is_deleted = 1 and cp.is_default=1 and cp.status=3
    set sp.unit_code = cp.unit_code --更新值
    where sp.unit_code is null and cp.unit_code is not null;

     where 条件放在最后,不然报错!

标签:code,多表,commodity,sp,update,mysql,cp,id,unit
来源: https://blog.csdn.net/damoneric_guo/article/details/121424562