Answers for "postgres multiple left join causing duplicates jsonb_agg"

SQL
0

postgres multiple left join causing duplicates jsonb_agg

SELECT tbl_a.id, tbl_a.name,
       COALESCE( ( SELECT json_agg(tbl_b.*)
                     FROM tbl_b 
                    WHERE tbl_b.a_id = tbl_a.id ), '{}'::json),
       COALESCE( ( SELECT json_agg(tbl_c.*)
                     FROM tbl_c 
                    WHERE tbl_c.a_id = tbl_a.id ), '{}'::json)
  FROM tbl_a;
Posted by: Guest on September-06-2021

Code answers related to "postgres multiple left join causing duplicates jsonb_agg"

Code answers related to "SQL"

Browse Popular Code Answers by Language