当前位置: 代码迷 >> Sql Server >> update里的from后面能跟子查询么?解决办法
  详细解决方案

update里的from后面能跟子查询么?解决办法

热度:102   发布时间:2016-04-27 19:09:54.0
update里的from后面能跟子查询么?
update   table1
set
      name   =   t.name
      age     =   t.age
from   table2   t       ----此处能用子查询么?如:from(select   *   from   table2   where   ......)
where   id   =   t.id

------解决方案--------------------
update table1
set
name = t.name,
age = t.age
from
(select * from table2 where ......) t
where
table1.id = t.id
------解决方案--------------------
可以,加个别名吧
  相关解决方案