SELECT
(UserCourseProgress.TimeEnded - UserCourseProgress.TimeStarted) as SecondsSpent,
UserCourseProgress.UserId
FROM
UserCourseProgress
INNER JOIN UserRoles
ON UserCourseProgress.UserId = UserRoles.UserId
AND (UserRoles.SuperId = '123' OR UserRoles.UserId = '123')
I'm trying to optimise this query as it takes too long (mainly Copying Data To Tmp Table).
The structure is simple a table called UserCourseProgress and another one called UserRoles, they both have the UserId column in common and I'm selecting all userRoles that belong to a super user. Any ideas?
UserRoles.SuperIdandUserRoles.UserId, as well as on the FKUserCourseProgress.UserId