我有这个查询,它获取三个不同表的最大日期记录。我可以对这些表进行联合,让它们一起返回各自的日期。但是,我无法找到一种方法来选择返回的这三个记录中的最大值。有任何想法吗?
SELECT MAX (Date_submitted ) as a
FROM [AngelSQL] . [dbo]. [LSN_RESPONSES] , ACCOUNTS , LSN_ENTRIES , GB3_ASSOCIATIONS
where
LSN_RESPONSES . USER_ID = accounts . username
and LoginName = 'admin'
and TakenFromCourseId = 'TT-TC-TS-TD-Test-Test'
and LSN_RESPONSES . PARENT_ID = LSN_ENTRIES .ENTRY_ID
and LSN_RESPONSES . PARENT_ID = GB3_ASSOCIATIONS .LSN_ENTRY_ID
union
SELECT MAX ( dateEnd ) as a
FROM [AngelSQL] . [dbo]. [qti_assessment_attempt] ,dbo . ACCOUNTS, COURSES, qti_question_containers, GB3_ASSOCIATIONS
where accounts . PERSON_ID = qti_assessment_attempt .person_id
and
taken_from_course_container_id = courses. CONTAINER_ID
and
accounts .LoginName = 'admin'
and COURSES . COURSE_ID= 'TT-TC-TS-TD-Test-Test'
and qti_assessment_attempt . question_container_id = qti_question_containers. id
and qti_question_containers . entry_ID = GB3_ASSOCIATIONS .LSN_ENTRY_ID
union
SELECT MAX ( PostDate ) as a
FROM dbo . ACCOUNTS, DiscussionPost , DiscussionForum , GB3_ASSOCIATIONS
where
accounts .USERNAME = DiscussionPost. AuthorId
and
LoginName ='admin'
and
discussionpost . CourseContext = 'TT-TC-TS-TD-Test-Test'
and
DiscussionPost . ForumId = DiscussionForum .ForumId
and DiscussionForum . EntryId = GB3_ASSOCIATIONS .LSN_ENTRY_ID}