I have student and course buckets.
-
A_course:
[
{
“A_course”: {
“description”: “none”,
“id”: “1001”,
“location”: “uk”,
“name”: “ABC”,
}
},
{
“A_course”: {
“description”: “none”,
“id”: “1002”,
“location”: “uk”,
“name”: “DEF”,
}
},
{
“A_course”: {
“description”: “none”,
“id”: “1003”,
“location”: “uk”,
“name”: “GHI”,
}
}
] -
A_student:
[
{
“A_student”: {
“course”: “MS”,
“course_id”: “1001”,
“stud_id”: “S1”,
“stud_name”: “Student1”
}
},
{
“A_student”: {
“course”: “BE”,
“course_id”: “1002”,
“stud_id”: “S2”,
“stud_name”: “Student2”
}
},
{
“A_student”: {
“course”: “BE”,
“course_id”: “1002”,
“stud_id”: “S3”,
“stud_name”: “Student3”
}
},
{
“A_student”: {
“course”: “PHD”,
“course_id”: “1003”,
“stud_id”: “S4”,
“stud_name”: “Student4”
}
}
]
I need output like below:
[
{
“A_course”: {
“description”: “none”,
“id”: “1001”,
“location”: “uk”,
“name”: “ABC”,
“stud_ids”: [
“S1”
]
}
},
{
“A_course”: {
“description”: “none”,
“id”: “1002”,
“location”: “uk”,
“name”: “DEF”,
“stud_ids”: [
“S2”,
“S3”
]
}
},
{
“A_course”: {
“description”: “none”,
“id”: “1003”,
“location”: “uk”,
“name”: “GHI”,
“stud_ids”: [
“S4”
]
}
}
]
I got this output with the help of below three queries.
UPDATE A_course
SET stud_ids
= (SELECT RAW s.stud_id FROM A_student s JOIN A_course c ON c.id = s.course_id where s.course_id = “1001”)
where id=“1001”;
UPDATE A_course
SET stud_ids
= (SELECT RAW s.stud_id FROM A_student s JOIN A_course c ON c.id = s.course_id where s.course_id = “1002”)
where id=“1002”;
UPDATE A_course
SET stud_ids
= (SELECT RAW s.stud_id FROM A_student s JOIN A_course c ON c.id = s.course_id where s.course_id = “1003”)
where id=“1003” ;
but I want single query to get this out put.
Thanks in advance
-Siva