0

I have a table in hive

ID|Name

1 "a"

2 "b"

1 "c"

I want the output of a query to be like

1 "a,b"

2 "c"

according to id it must group the name How can i achieve the above in Hive?,is there any built-in function in hive for this? Any pointers will be of great help

Regards,

Amit_Hora
  • 716
  • 1
  • 8
  • 27
  • You may have have inverted `b` and `c` ids in your table sample. – merours Jun 26 '14 at 08:04
  • 1
    If you are looking for output like `1 a,c and 2 b`, then you can use `collect_set` function. The details are [here](http://stackoverflow.com/questions/24199258/concat-single-column-fields-using-group-by/24200459#24200459) – visakh Jun 26 '14 at 08:16
  • possible duplicate of [Combine multiple rows into one space separated string](http://stackoverflow.com/questions/3703740/combine-multiple-rows-into-one-space-separated-string) – merours Jun 26 '14 at 08:24
  • Thanks for the help using SELECT id, collect_set(name) FROM user GROUP BY id solved my problem got to know this after following the links shared in above comments – Amit_Hora Jun 26 '14 at 09:56

1 Answers1

0

As far as i understood you are basically looking for a kind of GROUP_CONCAT(sql function) in hive ...

You can achieve the same functionality by select ID , collect_set(Name) from tblname group by ID.

kanishka vatsa
  • 2,074
  • 18
  • 8