Hi,
What I'm trying to achieve is this:
id | name | value1
id | name | value2
id | name | value3
To look like this:
id | name | value1, value2, value3
I've been trying to use array_to_string, but having trouble with it because sometimes the third column is empty so I'm getting NULL array errors.
Any ideas
Added info:
Here's more or less what I've got right now:
Code:
SELECT
site.name,
site_contact.phone,
site_contact.fax,
site_contact.lastname || ' ' || site_contact.firstname AS contact_person,
site_contact.email
FROM
site
LEFT OUTER JOIN
site_contact
ON
site.siteid = site_contact.siteid
WHERE
site.code
IN
(list here)
ORDER BY
site.sitename ASC;
Now this understandably gives me results like so:
sitename | phone1 | | person1 | email1
sitename | | | person2 |
sitename | | | person3 |
sitename | phone4 | | person4 | email4
I would like to get this in a single row:
sitename | phone1, phone4 | | person1, person2, person3, person4 | email1, email4
What I had tried was something like this instead of the JOIN:
Code:
array_to_string(
array(
SELECT site_contact.phone FROM site_contact WHERE site_contact.siteid = site.siteid
), ', '
)
But it didn't work because of the NULL fields.