How to create a correlated update subquery in MS-Access?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:42:41

问题


I'm in the process of normalizing a few tables and I've added a surrogate primary key to a table called Exams which holds exam titles.

Previously, the child tables would just use the entire name of the exam as the FK entry.

Now that I've added a autonumbered field to the table, I want to update the entries that use it such as the table where the questions are from as there are over a thousand of them.

Going through each exam with a modified update once I find the name each time would take a while, so I decided to write a correlated subquery in a UPDATE query. The query looks like this:

UPDATE tblExamQuestion
SET ExamID = (SELECT ExamID FROM tblExam WHERE ExamName = tblExamQuestion.ExamName);

Unfortunately, once I write the subquery portion, Access refuses to give me the Run option and just displays the Design View, Datasheet View and SQL View for that query. However, it still displays the Update Query icon in the object explorer.

Is there a proper way to write this so that Access doesn't get upset?

Using: Access 2007 with a Access 2003 MDB database.


回答1:


Why not:

UPDATE tblExamQuestion
INNER JOIN tblExam 
ON tblExam.ExamName = tblExamQuestion.ExamName
SET tblExamQuestion.ExamID = tblExam.ExamID 


来源:https://stackoverflow.com/questions/3322504/how-to-create-a-correlated-update-subquery-in-ms-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!