Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sum problem
Message
 
To
11/05/2000 21:36:05
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00368840
Message ID:
00368970
Views:
21
Folks,

Here's what is happening. The sums are what the SELECT is asking for.

We have one Id the 1, in the T2 table tehre are three matching records on that ID, and in T3 there are two matching records. The joins produce a result of 6 records, the joining of T1 with T2 gives three and then joining T3 gives the 6, one of each of the 3 for each of the T3 records. A listing is below;
T1 RecNo    T2 Recno   T3 Recno  T2 Amount   T3 Amount
1               1         1         50           10
1               2         1         60           10
1               3         1         40           10
1               1         2         50           15
1               2         2         60           15
1               3         2         40           15
SUM                                300           75
A GROUP BY will not change this, it will only hide the actual records produced in the JOIN. Perhaps the following SELECT will be more appropriate for the job;
SELECT T1.Id, T2.Id, SUM(T2.Amount) ;
  FROM T1 INNER JOIN T2 ON T1.ID = T2.Fid ;
 UNION ALL ;
 SELECT T1.ID, T3.Id, SUM(T3.Amount) ;
   FROM T1 INNER JOIN T3 ON T1.ID = T3.Fid ...
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform