当前位置: 代码迷 >> Sql Server >> SQL 语句,怎么在 能不能在where 里嵌套查询
  详细解决方案

SQL 语句,怎么在 能不能在where 里嵌套查询

热度:76   发布时间:2016-04-27 11:21:04.0
SQL 语句,如何在 能不能在where 里嵌套查询?
我有两张表,
一张表是 User_id 和 name 
第二张有 user_id 和 score

我现在要根据 name 查询得到 user_id 
再按 user_id 来更新 score ,即update 语句。

能不能一次实现呢?即将查询嵌套在 update 语句里头呢?谢谢。

------解决方案--------------------
SQL code
update t2 set t2.score=?from t1 where t2.[user_id]=t1.[user_id] and t1.name = 'xxx'
------解决方案--------------------
SQL code
update 第二张表 set score=[yourvalue]where [user_id]=(select top 1 [user_id] from 第一张表 where [name]='yourname')
------解决方案--------------------
SQL code
udpate aset a.score=分数from a  inner join b a.id=b.id where b.name='名字'
  相关解决方案