1
(click on this box to dismiss)
How do I concatenate multiple rows into a single value?
I want to get the contents of the following table as a single comma separated value:
NAMES
-----
John
Paul
Marry
Steve
And the result should be 'John, Paul, Marry, Steve'
1
Answer
1
CREATE TABLE t(name VARCHAR(255));
INSERT INTO t VALUES ('John'),('Paul'),('Marry'),('Steve');
SELECT GROUP_CONCAT(name) as name FROM t;
See also http://www.cubrid.org/concat_different_row_columns which uses hierarchical functions like SYS_CONNECT_BY_PATH.
asked 2 years ago
viewed 593 times