joshcowan25
04/18/2022, 5:00 AMjoshcowan25
04/18/2022, 5:02 AMjoshcowan25
04/18/2022, 5:06 AMtourdownunder
04/18/2022, 5:38 AMtourdownunder
04/18/2022, 5:39 AMtourdownunder
04/18/2022, 5:43 AMsql
CREATE VIEW author_with_books AS
select a.*, array_agg(b.name) from author a left outer join books b ON b.author = a.id
group by a.*; -- not sure this is allowed
`
This will be a bit more complicated with your many to many table though the principle is the same.tourdownunder
04/18/2022, 5:55 AMsql
CREATE VIEW author_with_books AS
select
a.*,
(SELECT array_agg(row_to_json(b) from books b inner join bv ON b.id = bv.bookid where bv.authorid = a.id)
from author a;
joshcowan25
04/19/2022, 4:55 AMtourdownunder
04/19/2022, 11:51 AM