This query suppose to show student last event completed information with some other information, this information is stored in multiple tables, problem with this query is I am getting multiple results for each student instead of showing their most recent information. Last function doesnt support on the system i m working on. Can any help!!
SELECT ACCOUNTS.FIRST_NAME,COURSES.COURSE,MAX(LSN_RESPONSES.DATE_SUBMITTED) AS LAST_EVENT_DATE,LSN_OBJECTS.TITLE AS EVENT_TITLE
FROM ACCOUNTS RIGHT JOIN
(LSN_RESPONSES LEFT JOIN
(COURSES RIGHT JOIN
(LSN_ENTRIES RIGHT JOIN LSN_OBJECTS ON LSN_ENTRIES.[OBJECT_ID]=LSN_OBJECTS.[OBJECT_ID])
ON COURSES.[COURSE_ID]=LSN_ENTRIES.[COURSE_ID])
ON LSN_RESPONSES.[PARENT_ID]=LSN_ENTRIES.[ENTRY_ID])
ON ACCOUNTS.[USERNAME]=LSN_RESPONSES.[USER_ID]
WHERE ((COURSES.COURSE_ID LIKE '______-_____-__') OR (ISNUMERIC(COURSES.COURSE_ID)>0))
AND (COURSES.[COURSE_ID]!='00225')
AND (ACCOUNTS.[USER_ID] LIKE '%.%.%')
AND (ACCOUNTS.USER_ID NOT LIKE '%.0999.%')
AND (ACCOUNTS.USER_ID NOT LIKE '%.0888.%')
GROUP BY ACCOUNTS.FIRST_NAME,LSN_OBJECTS.TITLE,COURSES.COURSE
HAVING DateDiff(d, MAX(LSN_RESPONSES.DATE_SUBMITTED),GetDate())>4
ORDER BY ACCOUNTS.FIRST_NAME
SELECT ACCOUNTS.FIRST_NAME,COURSES.COURSE,MAX(LSN_RESPONSES.DATE_SUBMITTED) AS LAST_EVENT_DATE,LSN_OBJECTS.TITLE AS EVENT_TITLE
FROM ACCOUNTS RIGHT JOIN
(LSN_RESPONSES LEFT JOIN
(COURSES RIGHT JOIN
(LSN_ENTRIES RIGHT JOIN LSN_OBJECTS ON LSN_ENTRIES.[OBJECT_ID]=LSN_OBJECTS.[OBJECT_ID])
ON COURSES.[COURSE_ID]=LSN_ENTRIES.[COURSE_ID])
ON LSN_RESPONSES.[PARENT_ID]=LSN_ENTRIES.[ENTRY_ID])
ON ACCOUNTS.[USERNAME]=LSN_RESPONSES.[USER_ID]
WHERE ((COURSES.COURSE_ID LIKE '______-_____-__') OR (ISNUMERIC(COURSES.COURSE_ID)>0))
AND (COURSES.[COURSE_ID]!='00225')
AND (ACCOUNTS.[USER_ID] LIKE '%.%.%')
AND (ACCOUNTS.USER_ID NOT LIKE '%.0999.%')
AND (ACCOUNTS.USER_ID NOT LIKE '%.0888.%')
GROUP BY ACCOUNTS.FIRST_NAME,LSN_OBJECTS.TITLE,COURSES.COURSE
HAVING DateDiff(d, MAX(LSN_RESPONSES.DATE_SUBMITTED),GetDate())>4
ORDER BY ACCOUNTS.FIRST_NAME