本文介绍了我想用select语句(返回记录的某一行)中一个字段的值更新表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个临时表
我想使用select语句(返回记录的某些行)中的一个字段的值更新表?

i have a temp table
i want to update the table with value of one field from a select statement (that return some row of records)?
how can i do it?

推荐答案


Insert into [destinationTableName]
select [columns here] from [sourceTableName]


UPDATE MyTable
SET SomeColumn = (SELECT Something
                  FROM AnotherTable
                  WHERE ...)
WHERE filter for rows to update


请注意,选择更新列的选择最多会产生0或1行,否则该语句将失败.因此,最有可能需要使用相关查询(在要更新的表和要查询的表之间定义联接".


Note that the select updating the column most produce either 0 or 1 rows, otherwise the statement will fail. So most likely you need to use correlated query (you define a ''join'' between the table to update and the table that is queried.


这篇关于我想用select语句(返回记录的某一行)中一个字段的值更新表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 07:51