public static QuizResult getQuizResult(int QuizId, int UserId)
    {
        try
        {
            QuizResult qr = new QuizResult();
            String statement = String.format("select  qq.questionid ,coalesce(qr.ANSWERID, 0) AnswerID, q.questiontext, coalesce(qr.answertext, 'NONE') ANSWERTEXT, coalesce(qr.iscorrect, false) ISCORRECT, qca.answertext as correctanswer\n" +
"from quizquestion qq join question q on qq.QUESTIONID = q.QUESTIONID\n" +
"left outer join (select iq.QUESTIONID, iq.ANSWERID, iqa.AnswerText, iqa.iscorrect from quizresult iq \n" +
"join questionanswer iqa on iq.ANSWERID = iqa.ANSWERID and iq.QUESTIONID = iqa.QUESTIONID where userid = %d and quizid = %d) qr\n" +
"on qq.QUESTIONID = qr.QUESTIONID\n" +
"join (select answertext, questionid from questionanswer where iscorrect = true) qca\n" +
"on qq.QUESTIONID = qca.questionid\n" +
"where qq.quizid = %d" +
"",  UserId, QuizId, QuizId);
            
            ResultSet rs = getQueryResults(statement);
            while (rs.next())
            {
                QuizResultRow qrr = new QuizResultRow();
                qrr.questionText = rs.getString("QuestionText");
                qrr.isCorrect = rs.getBoolean("isCorrect");
                qrr.selectedAnswerText = rs.getString("Answertext");
                qrr.correctAnswerText = rs.getString("CorrectAnswer");
                qr.ResultRows.add(qrr);
            }
            return qr;
        }
        
        catch (SQLException ex)
        {   
            return null;
        }
        
    }