0

I have two tables,

1) USER

id fullname email 
1   abc      a@a.com
2   def      b@b.com

2) SKILLS

id  user_id skills 
1   1       writer
2   1       blogger
3   2       singer

I want to get result like bellow,

fullname    email       skills
abc       a@a.com    writer,blogger
abcd gef
  • 59
  • 1
  • 11

1 Answers1

0

You can use array_agg() function in query to get the results.

Select fullname, email, array_agg(skills) from user left join skills on user.id = skills.user_id group by (fullname, email)
  • thanks for reply. when i run query i am getting bellow error, "column user.fullname must appear in group by clause or be used in aggregage function" – abcd gef Jan 10 '18 at 04:44
  • Yes you have to add all the columns apart from array_agg in group by clause – Sagar Jagodra Jan 10 '18 at 06:43
  • I solved the issue by using bellow query,SELECT string_agg(skills,',') FROM users LEFT JOIN skills ON users.id = skills.user_id GROUP BY (fullname, email) – abcd gef Jan 10 '18 at 11:48
  • Great, String_agg and array_agg are two different functions with similar kind of functionality. Please do not forgot to upvote :P – Sagar Jagodra Jan 10 '18 at 14:29
  • Yes, I upvote and mark as accepted answer but i think you will have to edit the query based on group by close by adding array_agg functions. – abcd gef Jan 10 '18 at 15:41