Let's say I have the following two tables
Table 1
Column1 Column2 Column3
1 A ABC
1 B DEF
1 C DEF
1 D GHI
1 E GHI
2 A1 ABC
2 B1 DEF
2 C1 DEF
2 D1 GHI
Table 2
Column1 DEF GHI
X B D
X C D
X C E
X G D
Z B D
Two values of column 3 of table 1 are columns in Table 2, and these columns are populated with the data in table1.column2.
Now, I need to write an SQL query such that for each group in table 1 (groups based on table1.column1), I am able to get all the values in table 2 which consists of all the DEF values of the group in table2.column2 and all of the GHI values in table2.column3
For example, for the given table, my expected output should be only X. Because X has both B and C in column DEF and has both D and E in column GHI. Z, on the other hand, does not contain C in the DEF column.
Can someone guide me on how to proceed and how should I go about it?