Postgres to fetch the list having comma separated values

前端 未结 1 1247
小蘑菇
小蘑菇 2021-01-29 03:08

I am working on Postgres SQL and having below join query, when I execute this query I get two or 3 records for each employee, because each employee has 3 different types of emai

相关标签:
1条回答
  • 2021-01-29 03:31

    Aggregate by employee and use string_agg:

    select
        c.employee_id,         -- or just c.* assuming employee_id is a PK
        string_agg(ce.email, ',') as emails
    from root.employee c
    full outer join root.employee_email ce
        on c.employee_id = ce.employee_id
    group by
        c.employee_id
    order by
        c.employee_id
    limit 1000
    offset 0;
    
    0 讨论(0)
提交回复
热议问题