Hi! Could we please enable some services and cookies to improve your experience and our website?
create table questions (
id int primary key auto_increment,
question varchar(255)
);
create table question_options (
id int primary key auto_increment,
question_id int,
answer varchar(255)
);
insert into questions (question) values ('Question 1?'), ('Question 2?');
insert into question_options (question_id, answer) values
(1, 'Answer 1?'), (1, 'Answer 2?'),
(2, 'Answer 3?'), (2, 'Answer 4?');
select
q.question,
json_arrayagg(answer) answers
from questions q
join question_options qo on qo.question_id = q.id
group by q.id, q.question
;