我想在MS Access中使用单个更新查询来更新多个记录。我遵循了这个答案(https://stackoverflow.com/a/65027/2935885)中提到的使用单个查询插入多条记录的想法。
当我尝试这个查询时,它起作用了:
UPDATE my_table left join (select 'rowid' as col_1, 'updated_value' as col_2 from onerow) new_values ON my_table.col_1 = new_values.col_1 set my_table.col_2 = new_values.col_2(onerow是一个虚拟的空表)
然而,当我将它扩展到多个新值行时,MS Access给出了一个错误“操作必须使用可更新的查询”。
UPDATE my_table left join (
select 'rowid1' as col_1, 'updated_value1' as col_2 from onerow
union all
select 'rowid2' as col_1, 'updated_value2' as col_2 from onerow
union all
select 'rowid3' as col_1, 'updated_value3' as col_3 from onerow
) new_values ON my_table.col_1 = new_values.col_1 set my_table.col_2 = new_values.col_2如何解决这个问题?或者我所做的查询出了什么问题?
发布于 2018-09-03 19:46:41
不能将update查询与联合查询一起使用,因为整个行集需要是可更新的,而联合查询永远不能更新。
考虑使用顺序表而不是双(单行)表。序列表是一个用序列号填充的表。
如果你有一个包含100个数字的顺序表,你可以使用这样的东西:
UPDATE my_table left join (
select Choose(s.nr,'rowid1', 'rowid2', 'rowid3') as col_1, Choose(s.nr,'updated_value1','updated_value2','updated_value3') as col_2
from Sequence s
WHERE s.nr Between 1 And 3
) new_values ON my_table.col_1 = new_values.col_1 set my_table.col_2 = new_values.col_2https://stackoverflow.com/questions/52148983
复制相似问题