Skip to content
Advertisement

How to concatenate column values with matching column values in another column inside a case statement?

I would like to create hhID in my column based on values in NodeID. IF nodeID is empty, hhId should be a copy of UID, If not, then hhID should be a combination of all UIDs with the same values of nodeID.I have put dummy text here; ‘Nepal is there’. However, for UID, ‘JBGNARZ1’, hhID should be JBGNARZ1, JRL0UUOI.

enter image description here

I have tried using following code, but it concatenates all UIDs with empty nodeID values in a single string.

However, I need all UIDs intact in my first column. Could you please kindly help me?

Advertisement

Answer

You can use group_concat to achieve this:

UID nodeID hhID
A A
B 1 B,D
C 2 C
D 1 B,D

dbfiddle here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement