Search code examples
sqlselectgroup-byinterbase

Interbase SQL Select Group By Records into one row with commas


I have a simple Interbase SQL Select Group By query:

Select STRINGNAME from STRINGLIST
Group by STRINGNAME

This query returns this result:

STRINGNAME
FirstString
SecondString
ThirdString

and etc.

I would like to have my query return one row that does this in any order:

FirstString,SecondString,ThirdString

or inverted

ThirdString,SecondString,FirstString

How is it possible to do it? I was thinking of a procedure but maybe there is another more simple way?


Solution

  • I've found the answer myself. Thanks.

    Firebird and Interbase have a LIST() aggregate function which does just what I need:

    SELECT LIST(DISTINCT STRINGNAME, ',')
    FROM STRINGLIST
    

    This works perfectly for Interbase SQL and Firebird SQL