views:

53

answers:

0

Hello,
I want to get QuestionVersion with max versionNumber for each Question. Next I need to check status of those versions and get QuestionVersionContents associated with versions with correct status value. Following statement seems to work but I need It as criteria or at least HQL:

select c.content, c.language_id, qv.status, qv.versionNumber, qv.question_id from
    dbo.QuestionVersionContent c
        inner join
         (select v.id, v.status, v.versionNumber, v.question_id from dbo.QuestionVersion v
         inner join
          (select question_id, max(versionNumber) as versionNumber from dbo.QuestionVersion group by question_id) g
         on v.question_id = g.question_id and v.versionNumber = g.versionNumber) qv
        on c.questionVersion_id = qv.id where status='CORRECT';

database diagram: link text