I am working with a 3 way join that is giving me a cartesian result that I do not want. :-( There are two unique IDs in A and B. C provides the translation from ID to NAME. The TIME is stored in both A and B.
This query:
select C.NAME,
A.TIME,
A.DATA1, A.DATA2, A.DATA3,...
B.DATA1, B.DATA2, B.DATA3,...
from TABLE_A A,
TABLE_B B,
TABLE_C C
where C.ID = A.ID
and C.ID = B.ID
and A.TIME between '20010615090000' and '20010615150000'
and B.TIME between '20010615090000' and '20010615150000'
order by C.NAME,
A.TIME asc
returns the two names X 6 entries of each time.
NAME1,0800,DATA
NAME1,0800,DATA
NAME1,0800,DATA
NAME1,0800,DATA
NAME1,0800,DATA
NAME1,0800,DATA
NAME1,0900,DATA
NAME1,0900,DATA
NAME1,0900,DATA
NAME1,0900,DATA
NAME1,0900,DATA
NAME1,0900,DATA
NAME1,1000,DATA
NAME1,1000,DATA
NAME1,1000,DATA
NAME1,1000,DATA
NAME1,1000,DATA
NAME1,1000,DATA
NAME1,1100,DATA
NAME1,1100,DATA
NAME1,1100,DATA
NAME1,1100,DATA
NAME1,1100,DATA
NAME1,1100,DATA
NAME1,1200,DATA
NAME1,1200,DATA
NAME1,1200,DATA
NAME1,1200,DATA
NAME1,1200,DATA
NAME1,1200,DATA
NAME1,1300,DATA
NAME1,1300,DATA
NAME1,1300,DATA
NAME1,1300,DATA
NAME1,1300,DATA
NAME1,1300,DATA
NAME2,0800,DATA
NAME2,0800,DATA
NAME2,0800,DATA
NAME2,0800,DATA
NAME2,0800,DATA
NAME2,0800,DATA
NAME2,0900,DATA
NAME2,0900,DATA
NAME2,0900,DATA
NAME2,0900,DATA
NAME2,0900,DATA
NAME2,0900,DATA
NAME2,1000,DATA
NAME2,1000,DATA
NAME2,1000,DATA
NAME2,1000,DATA
NAME2,1000,DATA
NAME2,1000,DATA
NAME2,1100,DATA
NAME2,1100,DATA
NAME2,1100,DATA
NAME2,1100,DATA
NAME2,1100,DATA
NAME2,1100,DATA
NAME2,1200,DATA
NAME2,1200,DATA
NAME2,1200,DATA
NAME2,1200,DATA
NAME2,1200,DATA
NAME2,1200,DATA
NAME2,1300,DATA
NAME2,1300,DATA
NAME2,1300,DATA
NAME2,1300,DATA
NAME2,1300,DATA
NAME2,1300,DATA
If I change the where clause to this:
where C.ID = A.ID
and C.ID = B.ID
and A.TIME between '20010615090000' and '20010615150000'
and A.TIME = B.TIME
the result is
NAME2,0800,DATA
NAME2,0900,DATA
NAME2,1000,DATA
NAME2,1100,DATA
NAME2,1200,DATA
NAME2,1300,DATA
As you may have surmised I am trying to get DATA for each TIME for each NAME.
NAME1,0800,DATA
NAME1,0900,DATA
NAME1,1000,DATA
NAME1,1100,DATA
NAME1,1200,DATA
NAME1,1300,DATA
NAME2,0800,DATA
NAME2,0900,DATA
NAME2,1000,DATA
NAME2,1100,DATA
NAME2,1200,DATA
NAME2,1300,DATA
Any help would be appreciated.
Regards
This query:
select C.NAME,
A.TIME,
A.DATA1, A.DATA2, A.DATA3,...
B.DATA1, B.DATA2, B.DATA3,...
from TABLE_A A,
TABLE_B B,
TABLE_C C
where C.ID = A.ID
and C.ID = B.ID
and A.TIME between '20010615090000' and '20010615150000'
and B.TIME between '20010615090000' and '20010615150000'
order by C.NAME,
A.TIME asc
returns the two names X 6 entries of each time.
NAME1,0800,DATA
NAME1,0800,DATA
NAME1,0800,DATA
NAME1,0800,DATA
NAME1,0800,DATA
NAME1,0800,DATA
NAME1,0900,DATA
NAME1,0900,DATA
NAME1,0900,DATA
NAME1,0900,DATA
NAME1,0900,DATA
NAME1,0900,DATA
NAME1,1000,DATA
NAME1,1000,DATA
NAME1,1000,DATA
NAME1,1000,DATA
NAME1,1000,DATA
NAME1,1000,DATA
NAME1,1100,DATA
NAME1,1100,DATA
NAME1,1100,DATA
NAME1,1100,DATA
NAME1,1100,DATA
NAME1,1100,DATA
NAME1,1200,DATA
NAME1,1200,DATA
NAME1,1200,DATA
NAME1,1200,DATA
NAME1,1200,DATA
NAME1,1200,DATA
NAME1,1300,DATA
NAME1,1300,DATA
NAME1,1300,DATA
NAME1,1300,DATA
NAME1,1300,DATA
NAME1,1300,DATA
NAME2,0800,DATA
NAME2,0800,DATA
NAME2,0800,DATA
NAME2,0800,DATA
NAME2,0800,DATA
NAME2,0800,DATA
NAME2,0900,DATA
NAME2,0900,DATA
NAME2,0900,DATA
NAME2,0900,DATA
NAME2,0900,DATA
NAME2,0900,DATA
NAME2,1000,DATA
NAME2,1000,DATA
NAME2,1000,DATA
NAME2,1000,DATA
NAME2,1000,DATA
NAME2,1000,DATA
NAME2,1100,DATA
NAME2,1100,DATA
NAME2,1100,DATA
NAME2,1100,DATA
NAME2,1100,DATA
NAME2,1100,DATA
NAME2,1200,DATA
NAME2,1200,DATA
NAME2,1200,DATA
NAME2,1200,DATA
NAME2,1200,DATA
NAME2,1200,DATA
NAME2,1300,DATA
NAME2,1300,DATA
NAME2,1300,DATA
NAME2,1300,DATA
NAME2,1300,DATA
NAME2,1300,DATA
If I change the where clause to this:
where C.ID = A.ID
and C.ID = B.ID
and A.TIME between '20010615090000' and '20010615150000'
and A.TIME = B.TIME
the result is
NAME2,0800,DATA
NAME2,0900,DATA
NAME2,1000,DATA
NAME2,1100,DATA
NAME2,1200,DATA
NAME2,1300,DATA
As you may have surmised I am trying to get DATA for each TIME for each NAME.
NAME1,0800,DATA
NAME1,0900,DATA
NAME1,1000,DATA
NAME1,1100,DATA
NAME1,1200,DATA
NAME1,1300,DATA
NAME2,0800,DATA
NAME2,0900,DATA
NAME2,1000,DATA
NAME2,1100,DATA
NAME2,1200,DATA
NAME2,1300,DATA
Any help would be appreciated.
Regards