我有2个表,table_a
和table_b
。我想从user_id
获取table_a
并更新table_b
中user_id
的记录。像这样:
Select * from table_a where user_id ="Ken"
if result is 22
Update score = 1 where id = 22.
这些查询有效但我希望将它们合二为一。谁能告诉我这样做的最佳方法是什么?
答案 0 :(得分:6)
试试这个应该可行,
UPDATE table_b
SET score=1
WHERE id = (select id from table_a where user_id ="Ken")
答案 1 :(得分:3)
UPDATE table_b SET score = 1
WHERE id IN (SELECT * FROM table_a WHERE user_id = "Ken")
答案 2 :(得分:1)
IF EXISTS (Select * from table_a where user_id ="Ken" )
If result=22
BEGIN
UPDATE table_a SET score = 1
END