I have this kind of information on a db table
COMPANY USER MYDATA
_______________ _______________
AA
01 AA01
USER AAUS
01 USER AA01US
BB
02 BB02
GROUP BBGR
02 GROUP BB02GR
USER is a "logical" reference to another table like this one:
USER GROUP
_______________ _____
USER GROUP
USER2 GROUP2
USER3 GROUP
I want retrieve column (MYDATA) according company and user/group.
For example:
If I have COMPANY = 01 and USSER = USER, I want retrieve row with
MYDATA value = AA01US
If I have COMPANY = KK and USSER = USER, I want retrieve row with
MYDATA value = AAUS
If I have COMPANY = 01 and USSER = USER2, I want retrieve row with
MYDATA value = AA01
If I have COMPANY = KK and USSER = USER2, I want retrieve row with
MYDATA value = AA
If I have COMPANY = KK and USSER = USER3, I want retrieve row with
MYDATA value = BBGR (because USER3 is part of GROUP)
What is the best way (for performance purpose) to retrieve it?
Maybe I can also change my table structure.
I prefer to avoi many select statements to retrive this information.
I'm using db2 8 and 9 on windows platform and DB2/400 on v5r3
Thank You
Roberto