本文介绍了用其他表的结果更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我有一张表格,其中包含一组学生数据(学生)和一张新表格(申请人).这些表中的列为:

学生:
Stud_Id
Stud_Name
Institute_Id

申请者:
App_Id
App_Name
Inst_Id

Stud_Id和App_Id是相同的数据集.我现在要做的是更新Applicants表,我想使用Students.Stud_Id = Applicants.App_Id将Institute_Id插入Inst_Id.

我尝试了一下.但是错误出来了.我该如何解决?

HiI have a table which consists of a set of students data(Students) and a new table (Applicants). The columns in those tables are:

Students:
Stud_Id
Stud_Name
Institute_Id

Applicants:
App_Id
App_Name
Inst_Id

Stud_Id and App_Id are the same dataset. What I am going to do now is i want to update Applicants table, which I want to insert Institute_Id into Inst_Id using Students.Stud_Id = Applicants.App_Id.

I have tried a little. But error came out. How can i fix this?

UPDATE a SET a.Inst_Id = (select s.Institute_Id from Applicants a inner join Students s on a.App_Id = s.Stud_Id)
FROM Applicants a
INNER JOIN Students s ON a.App_Id = s.Stud_Id

推荐答案

UPDATE a SET a.Inst_Id = s.Institute_Id 
FROM Applicants a
INNER JOIN Students s ON a.App_Id = s.Stud_Id


这篇关于用其他表的结果更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 17:17