首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-09-23 
SQL 语句,如何在 能不能在where 里嵌套查询?我有两张表,一张表是 User_id 和 name第二张有 user_id 和 sco

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='名字' 

热点排行