开发者社区 问答 正文

mysql如何更新一个多表查询出来的字段

$sql = 'SELECT c.is_check' .
                ' FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
                ' LEFT JOIN ' . $GLOBALS['ecs']->table('cart') . ' AS c ON c.goods_id = g.goods_id ' .
                ' WHERE g.enter_mode = 3105 AND c.user_id = $user_id';

如上 sql 语句是通过 cart 表和 goods 表的一些条件查询出 cart 表中符合条件的 is_check 字段。
我现在想将这个字段里的值统一更新为我前台传过来的 $is_chick,该怎么实现尼?

或者说能不能直接用 updata 语句实现尼?

展开
收起
a123456678 2016-07-04 17:35:10 2939 分享 版权
1 条回答
写回答
取消 提交回答
  • 类似这样,sql语句你自己需要调试

    update cart d set d.is_check = $is_chick
    
    where exists(
    SELECT 1 FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
                    ' LEFT JOIN ' . $GLOBALS['ecs']->table('cart') . ' AS c ON c.goods_id = g.goods_id ' .
                    ' WHERE g.enter_mode = 3105 AND c.user_id = $user_id and c.id=d.id)
    2019-07-17 19:50:58
    赞同 展开评论