Starting from this table structure:
Code:
K1 K2 K3 K4 K5 V1 V2
-----------------------------------
AA BB C1 D1 D2
AA KK C1 D1 D2
01 AA KK C1 D101 D201
01 GR AA KK C1 D101GR D201GR
AA KK C2 D1 D2
01 AA KK C2 D101 D2
US AA KK C2 D1US D2
01 US AA KK C2 D101US D2
02 AA KK C2 D102 D2
GR AA KK C2 D1GR D2
02 GR AA KK C2 D102GR D2
01 GR AA KK C2 D101GR D2
01 AA KK C4 D101 D201
AA KK C5 D1 D2
where K1, K2, K3, K4 and K5 are the unique primary key of the table
I want retrieve all row where:
K3 = AA
K4 = KK
and for K1=01 and K2=US
K2 is a "logical" reference to another table User/Group
Code:
USER GROUP
____________________
US GR
USER2 GROUP2
USER3 GROUP
So in this case 4 rows must be returned: one for K5 = C1 and another
one for K5=C2
I don't know how many rows will be returned because i don't know how
many K5 value will be for K1-K4 keys
Wished Results table
Code:
K1 K2 K3 K4 K5 V1 V2
-----------------------------------
01 GR AA KK C1 D101GR D201GR
01 US AA KK C2 D101US D2
01 AA KK C4 D101 D201
AA KK C5 D1 D2
What kind of "crazy" SQL i must do to have it?
Thank You !
Roberto