Note that there are some explanatory texts on larger screens.

plurals
  1. POCombining multiple rows to one
    primarykey
    data
    text
    <p>I'm attempting to combine multiple names across rows to one column when the project_id matches. I started with a self join but could not get it to work the way I wanted it to and I'm pretty certain there is a function or cte that can do this a lot easier. Asking for direction. Working with db2.</p> <p>Here is what I have so far which doesnt work and is producing a -104 error.</p> <pre><code> ( SELECT DP.D_P_ID, DP.project_name, DU2.NAME_LAST CONCAT ', ' CONCAT DU2.NAME_FIRST AS FROM Fact_table as FAT INNER JOIN D_P DP ON FAT.D_P_ID = DP.D_P_ID INNER JOIN B_U_P BUP on DP.D_P = BUP.D_P_ID INNER JOIN D_U DU2 ON BUP.D_U_ID = DU2.D_U_ID INNER JOIN D_Date DD ON FAT.START_DATE_ID = DD.DATE_KEY INNER JOIN D_A DA ON FAT.D_A_ID = DA.D_A_ID WHERE (( (DD.DATE_VALUE &gt;= '2013-01-01') OR (DD.DATE_VALUE &lt; '2014-01-01') OR (DD.DATE_VALUE &lt;= '2013-01-01'))) AND DA.M_NAME = 'Mandy' AND BUP.USER_FLAG = 'Y' GROUP BY DP.D_P_ID, DP.project_name, DU2.NAME_LAST CONCAT ', ' CONCAT DU2.NAME_FIRST ORDER BY DP.project_name ) PI1 join ( SELECT DP.D_P_ID, DP.project_name, DU2.NAME_LAST CONCAT ', ' CONCAT DU2.NAME_FIRST AS FROM Fact_table as FAT INNER JOIN D_P DP ON FAT.D_P_ID = DP.D_P_ID INNER JOIN B_U_P BUP on DP.D_P = BUP.D_P_ID INNER JOIN D_U DU2 ON BUP.D_U_ID = DU2.D_U_ID INNER JOIN D_Date DD ON FAT.START_DATE_ID = DD.DATE_KEY INNER JOIN D_A DA ON FAT.D_A_ID = DA.D_A_ID WHERE (( (DD.DATE_VALUE &gt;= '2013-01-01') OR (DD.DATE_VALUE &lt; '2014-01-01') OR (DD.DATE_VALUE &lt;= '2013-01-01'))) AND DA.M_NAME = 'Mandy' AND BUP.USER_FLAG = 'Y' GROUP BY DP.D_P_ID, DP.project_name, DU2.NAME_LAST CONCAT ', ' CONCAT DU2.NAME_FIRST ORDER BY DP.project_name ) PI2 on PI1.d_p_id = PI2.d_p_id </code></pre> <p>Data example: <img src="https://i.stack.imgur.com/Gagwx.png" alt="enter image description here"></p> <p>This is the result that I need: <img src="https://i.stack.imgur.com/F6Hdc.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload