I am developing a training management web-based system that provides the user with short quizzes to refresh their knowledge. Anyway, I have the following database design:
Employee Table: Username, Name, DivisionCode
Divisions Table: SapCode, DivisionShortcut
Quiz Table: QuizID, Title, IsSent
Question Table: QuestionID, Question, QuizID...
UserQuiz Table: UserQuizID, QuizID, Username, Score.
I was be able to come up with a query that shows the names of all non-participants in all divisions just in the last quiz. What I want now is to show the non-participants names in all quizzes that have been sent to the users to participate in them. The results should be listed grouping by quiz title and DivisionShortcut. So how to do that?
My Query:
SELECT d.DivisionShortcut, e.Name
FROM employee e
join Divisions d on (e.DivisionCode = d.SapCode)
left join (select A.QuizID, a.Username
from UserQuiz a join
(select max(QuizID) QuizID from dbo.Quiz where IsSent=1) b
on a.QuizId = b.QuizID ) c
on e.Username = c.Username
WHERE c.QuizID is null
Order By d.DivisionShortcut
You can use
CROSS JOINto get all combinations of employee and Quiz, then useNOT EXISTSto eliminate all combinations that have been completed: