sonooby
sonooby

Reputation: 43

What is the purpose of ON TRUE when doing a LEFT JOIN LATERAL statement here?

I have the following query statement, but why the on true is required is unclear.

[question]

id text
1 Boba Fett is a...

[question_option]

id question_id text correct
1 1 Jedi false
1 1 Sith false
1 1 Mandalorian true
select question.id
     , "question_option"."data" as "options"
from question
left join lateral
    (select json_agg(
                json_build_object( 'id',     "question_option"."id"
                                  ,'text',   "question_option"."text"
                                  ,'correct',"question_option"."correct"
                )
            ) as "data"
     from question_option
     where "question_option".question_id = question.id) as "question_option" on true
where question.quiz_id = '1';

Upvotes: 1

Views: 54

Answers (0)

Related Questions