I have this set of tables:
users table:
id username
1 user
groups table:
id name
1 g1
2 g2
users_groups table:
user_id group_id
1 1
1 2
and i want to obtain this result:
id username user_groups
1 user g1,g2
i found that using string_agg would solve the problem, and it did on postgres console, but when i used the same query on php i got this message
SQLSTATE[HY000]: General error: 1 no such function: string_agg
here's my query:
select users.id, users.username, string_agg(groups.name, ', ')
from users
inner join users_groups on users.id = users_groups.user_id
inner join groups on groups.id = users_groups.group_id
group by users.id
by the way I'm using:
- postgresql-9.3
- php 5.6.0
- apache 2
- windows 7
- laravel 5.0