Results 1 to 4 of 4

Thread: SUM() for strings

  1. #1
    Join Date
    Sep 2011
    Posts
    4

    Question SUM() for strings

    Hi,
    Is it possible to write function like SUM() but for strings?
    I have a table categories with fields id, name, parent_id
    and I need a query something like this:
    Code:
    select *, STR_SUM(categories.name) as cat_name from categories
            group by categories.parent_id
    where STR_SUM() - a function for string concatenation.
    It has to return a list like this: 'cat1, cat2, cat3'
    Thanks!

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    For SQL Server you can use FOR XML PATH() statement to achieve that.

  3. #3
    Join Date
    Sep 2011
    Posts
    4
    How to do this for MySQL Server?
    I'm using MySQL Server 5.5.

  4. #4
    Join Date
    Sep 2011
    Posts
    4
    I've solved the problem using GROUP_CONCAT
    http://dev.mysql.com/doc/refman/5.0/...functions.html

Posting Permissions

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