Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Location
    Hong Kong
    Posts
    15

    Unanswered: How to concatenate?

    Hello dears,

    For example, I have a table contains records as follows:
    table1
    ID Name Remark
    1001 Sam M1234
    1001 Sam N1234
    1001 Sam O1234
    1002 Rita X1234
    1002 Rita Y1234
    1002 Rita Z1234

    The output I want is as follows:
    select id, remark from table1 group by id

    ID Remark
    1001 M1234N1234O1234
    1002 X1234Y1234Z1234

    Anybody can help how to build a select statement to concatenate text of different records?

    Thanks
    Sarbeswar

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    in 4.1+ you can use the GROUP_CONCAT function

    otherwise you have to write a script to loop over the result set
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •