1

我有 2 张桌子,table_a并且table_b. 我想从中获取user_idtable_a更新记录table_buser_id像这样的东西:

Select * from table_a where user_id ="Ken"

if result is 22 

Update score = 1 where id = 22. 

这些查询有效,但我想将它们组合在一起。谁能告诉我最好的方法是什么?

4

3 回答 3

6

试试这个应该可以,

UPDATE table_b
SET score=1
WHERE id = (select id from table_a where user_id ="Ken")
于 2012-06-24T05:34:53.967 回答
3
UPDATE table_b SET score = 1
WHERE id IN (SELECT * FROM table_a WHERE user_id = "Ken")
于 2012-06-24T05:35:28.773 回答
1
IF EXISTS (Select * from table_a where user_id ="Ken" )
If result=22
BEGIN
UPDATE table_a SET score = 1
END
于 2012-06-24T05:38:27.910 回答