美文网首页
update方法使用集合

update方法使用集合

作者: 一梦三四年lyp | 来源:发表于2019-05-25 11:21 被阅读0次

update应该是mysql里最常用的sql之一了,在开发过程中总结了以下几种写法

1,简单类型

  语句结构
  update  table  set   where
  示例:
  update product SET order_count = 2 WHERE id = 1

2,多表类型

  语句结构
  update table1,table2 set table1.col = table2.col where 
  示例:
  update product as p,`order` as o SET p.id = o.product_id WHERE id = 1

3,子查询类型

  语句结构
  update table1,(select * from table) a set table1.col = a.col 
  示例:
  UPDATE product as p,
( SELECT count( order_id ) AS order_count FROM `order` WHERE     product_id = 1 ) AS o 
SET p.order_count = o.order_count 
WHERE
id = 1 

相关文章

网友评论

      本文标题:update方法使用集合

      本文链接:https://www.haomeiwen.com/subject/sneazqtx.html