Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Group By does not return right result with multiple tabl
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01186807
Message ID:
01186933
Views:
23
This message has been marked as the solution to the initial question of the thread.
You got exactly what you ask for :-)
The doubled result in the result is because the recordset looks like this (Lets change the second 10 in the crsTest1 to 11):
Fld1     Test1.Ammount   Test2.Ammount
---------------------------------------
1            10                100
1            11                100
You got as many records as the largest number of records in all tables. In VFP9 you could use derived tables to got the result you want, I am not sure about VFP8 (can't test it right now).
Here VFP9 query:
SELECT crsTest.Fld1, cTest1.Amnt AS Ammount1, cTest2.Amnt AS Ammount2;
       FROM crsTest;
INNER JOIN (SELECT Fld1, SUM(Ammount) AS Amnt;
                   FROM crsTest1;
                   GROUP BY Fld1) cTest1;
ON crsTest.Fld1 = cTest1.Fld1;
INNER JOIN (SELECT Fld1, SUM(Ammount) AS Amnt;
                   FROM crsTest2;
                   GROUP BY Fld1) cTest2;
ON crsTest.Fld1 = cTest2.Fld1
If this didn't works in VFP8, you could first query second two tables and then join the results to main one.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform