Discussion:
[h2] Combine multiple row's records in one row
Akanksha Chawla
2018-11-16 16:28:13 UTC
Permalink
I have a table (name- tbl2) with 21 column but I want to combine multiple
rows records in a row by using a unique reference number as below:

*Table Field and Records Type*

[image: enter image description here] <Loading Image...>

*Expected Result:*

[image: enter image description here] <Loading Image...>

Please help me to resolve this issue
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+***@googlegroups.com.
To post to this group, send email to h2-***@googlegroups.com.
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
Evgenij Ryazanov
2018-11-18 04:07:06 UTC
Permalink
Hello.

You need either
SELECT ID, ARRAY_AGG(DISTINCT Item) Item FROM tbl2 GROUP BY ID
or
SELECT ID, GROUP_CONCAT(DISTINCT Item SEPARATOR ', ') Item FROM tbl2 GROUP
BY ID
depending on data type of expected result. Use ARRAG_AGG for ARRAY result
or GROUP_CONCAT for VARCHAR result.

ARRAY_AGG is not available before H2 1.4.197, so use a recent version of H2.
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database+***@googlegroups.com.
To post to this group, send email to h2-***@googlegroups.com.
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
Loading...