Reputation: 43
I have the following query statement, but why the on true
is required is unclear.
id | text |
---|---|
1 | Boba Fett is a... |
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