How to Concatenate Column Values from Different Rows

Sometimes you want to concatenate all column values from differenct rows returned by your SELECT statement in one value. For example, consider the code table in the demodb database that comes by default with CUBRID:

SELECT s_name FROM code;

The above SQL query returns six values:

s_name
------
X
W
M
B
S
G

But you want to see the column values from all returned rows as a single concatenated string like:

s_name
------
XWMBSG

Or sometimes separated by comma, comma and a space, or other delimiters like:

s_name
------
X, W, M, B, S, G

So, how do we do this in CUBRID?

CUBRID has a bulit-in function called SYS_CONNECT_BY_PATH() which takes two arguments: a column name, and a delimiter. This function returns a string that represents the concatenation of all the values obtained by the SELECT query.