2

I have a table with an ID column that can contain duplicates, as it's used as a foreign key to match against my main table. There can be multiple results per id, as per the example below:

ID      FieldValue
1       This
2       Also this
1       and that
3       And additionally, this.
2       and, finally, this.

How would I go about merging the FieldValue column so that there was only one row per ID? E.g.

ID      FieldValue
1       This;and that
2       Also this;and, finally, this.
3       And additionally, this.

I wouldn't be concerned if the duplicate rows had to remain, e.g.

ID      FieldValue
1       This;and that
2       Also this;and, finally, this.
1       This;and that
3       And additionally, this.
2       Also this;and, finally, this.

As I could just run a DISTINCT query on them now that they're truly duplicates. Have been Googling for a while to no results; I suspect because it's something that has a few steps to it and I need to know what those steps are before a search would be fruitful.

Any ideas?

Sinister Beard
  • 3,570
  • 12
  • 59
  • 95
  • 1
    Thanks, @GordThompson, that's solved it. I was phrasing it wrong, but will leave this question here in case anyone else also phrases it wrong! – Sinister Beard Feb 13 '14 at 09:37

1 Answers1

0

If you are using mysql you can try something like this:

SELECT GROUP_CONCAT(FiledValue) As Result FROM tablename WHERE ID= '1'
Jag
  • 291
  • 1
  • 4