I'm working on Oracle SQL-Developer.
Let's start with data to better describe my issue. I have a table with 2 columns
USER
JOB
The relationship between those 2 is 1,n. So 1 user can relate to 1 or more JOB and 1 JOB be related to 1 or more USER.
Here a sample of the data :
USER JOB
1 A
1 B
1 C
1 D
1 E
2 B
2 C
2 F
2 G
3 A
3 B
3 C
3 D
4 I
4 J
4 K
4 L
The idea is to retrieve interconnected values all together. First of all, I though about LISTAGG that can concatenate and group values. But I'm obtaining this kind of result:
USER JOB
1 A, B, C, D, E
2 B, C, F, G
3 A, B, C, D
4 I, J, K, L
OR
USER JOB
1, 3 A
1, 2, 3 B
1, 2, 3 C
1, 3 D
1 E
2 F
2 G
4 I
4 J
4 K
4 L
The desired output is the following:
USER JOB
1, 2, 3 A, B, C, D, E, F, G
4 I, J, K, L
The idea is that if a user shares one job with someone else, then all jobs are linked all together even if all JOBS are not the same.
Example: USER_1 has 2 jobs A and B. USER_2 has 2 jobs B and C. Then USER_1 and USER_2 share jobs A, B, C.
Reversely, if a job shares one user with another job, then all users are linked all together even if all USERS are not the same...
So I've tried self join in order to retrieve all job for one given user and all users for one job given in order to display all possible shared values, but maybe it's the wrong way because I'm still blocked with LISTAGG. I've thought about PIVOT too but not tried it yet.
I hope I made this clear. What do you all think?
