Jooq:在三个 table 连接中加入相同的 table 两次

Jooq: Joining the same table twice across a three table join

所以我有三个 tables

Parent_section(id)

Assessment_Question(id,parent_section_id)

Assessment_Answer(id,assessment_question_id)

我正在尝试内连接 parent_section 和 assessment_qestion,左连接 assessment_question 和 assessment_Answer

到目前为止加入 parent_Section 和 assessment_question 我有这个,不知道如何做第三个 table?

    var queryResult= dsl.select()
    .from(PARENT_SECTION)
    .join(ASSESSMENT_QUESTION)
    .on(PARENT_SECTION.ID.eq(ASSESSMENT_QUESTION.PARENT_SECTION_ID))
    .where(PARENT_SECTION.GATE_ID.eq(gateId))
    .fetch()

只需添加另一个连接,您可以在普通连接中添加另一个连接 SQL:

var queryResult = dsl.select()
    .from(PARENT_SECTION)
    .join(ASSESSMENT_QUESTION)
    .on(PARENT_SECTION.ID.eq(ASSESSMENT_QUESTION.PARENT_SECTION_ID))
    .leftJoin(ASSESSMENT_ANSWER)
    .on(ASSESSMENT_QUESTION.ID.eq(ASSESSMENT_ANSWER.ASSESSMENT_QUESTION_ID))
    .where(PARENT_SECTION.GATE_ID.eq(gateId))
    .fetch()