For example:- I have 3 tables .
student :
student_id | name | rollNo | class 1 | a1 | 12 | 5 2 | b1 | 11 | 5 address: there can be multiple address for a user
street | district| country |student_id gali1 | nanit | india | 1 gali2 | nanital | india | 1 Books : There can be muliple book for the user
book | book_id |student_id history | 111 | 1 Science | 112 | 1 This is example . I want data to be like this in output . If i select for student_id 1. Then this would be result
student_id | name | rollNo | class | addresslist | booklist 1 | a1 | 12 | 5 | some sort of | some sort of | list which | list which | contain both| contain both | the address | the book detail | of user | of user I am using 12.1 which does not support json for now it is in 12.2 .
addresslist can be like this you can create list as you want but it should have all this data.
[{street:"gali1","distict":"nanital","country":"india","student_id":1},{"street":"gali2","distict":"nanital","country":"india","student_id":1}] same for booklist
Thanks in advance .
student_idand uselistaggand string concatenation||to get the string of addresses and books.listagg()built-in function, smth like thisselect s.student_id, s.name, s.rollno, s.class , listagg(a.country || ' ' || a.district || ' ' || a.street) within group (order by a.country) as addresslist , listagg(b.book_id || ' ' || b.book) within group (order by a.book_id) as booklist from student s , address a, books b where s.student_id = a.student_id and s.student_id = b.student_id;group by could be added as well.group by s.student_id, s.name, s.rollno, s.class;