嗨,我有一个看起来像这样的表之间的 UNION:
SELECT GetStudentClassmates.AvatarFileName as AvatarFileName,
GetStudentClassmates.UserName as UserName,
GetStudentClassmates.RoleId as RoleId
FROM GetStudentClassmates
WHERE GetStudentClassmates.StudentId = @studentId
UNION
SELECT GetStudentTeachers.AvatarFileName as AvatarFileName,
GetStudentTeachers.UserName as UserName,
GetStudentTeachers.RoleId as RoleId
FROM GetStudentTeachers
现在我需要将 UNION 的结果与其他表连接起来,并在最终结果中添加另一列。
这是我正在使用的 JOIN 代码
LEFT OUTER JOIN Sync_StudentAssignments as StudentAssignments
ON @studentId = StudentAssignments.StudentID
AND StudentAssignments.Deletion_Date IS NULL
LEFT OUTER JOIN Sync_StudentAssignmentInstances as StudentAssignmentInstances
ON StudentAssignments.StudentAssignmentID = StudentAssignmentInstances.StudentAssignmentID
AND StudentAssignmentInstances.Deletion_Date IS NULL
我的问题是我不知道必须在哪里添加选择代码,我认为这看起来像这样:
SELECT StudentAssignmentInstances.ModuleInstanceId
我的决赛桌应该有以下列:
AvatarFileName,
UserName,
RoleId,
ModuleInstanceId
我怎样才能做到这一点?