Search
 
SCRIPT & CODE EXAMPLE
 

SQL

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;
Comment

PREVIOUS NEXT
Code Example
Sql :: how to save result of sqlite query in a table 
Sql :: homebrew nysql launch 
Sql :: script to run SP_SPACESED on all tables in DB 
Sql :: influxdb clone measurement 
Sql :: Un mask mysql 
Sql :: sql create text column limited values 
Sql :: t-sql update table variale 
Sql :: basic structure of sql expression having clause 
Sql :: convert db timestamp to date 
Sql :: get who is hired in specific month in sql 
Sql :: error-expression-select-list-not-group-by-nonaggregated-column/ 
Sql :: mssql get running queries by spid 
Sql :: oracle database connection visual studio 2019 
Sql :: oracle alter database open restricted session 
Sql :: Having trouble running COUNT in my INSERT INTO statement 
Sql :: what is unsigned mysql 
Sql :: SQL Injection Using Multiple Statement 
Sql :: mysql get last character of string 
Sql :: sql count return 0 if no rows 
Sql :: database create table date of birth data type 
Sql :: delete hangfire retries list 
Sql :: alter server set options dbserver oracle fdw 
Sql :: difference between on and where in sql 
Sql :: oracle pl/sql check if file exists 
Sql :: mostrar datos de tablas relacionadas mysql kjava 
Sql :: azure sql server check foreign key 
Sql :: What logs are available on RDS MySQL? 
Sql :: report in database 
Sql :: plsql listagg 
Sql :: postgres regex word boundary 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =