Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multi Table View Problem
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Multi Table View Problem
Miscellaneous
Thread ID:
00525660
Message ID:
00525660
Views:
41
I am trying to create one view which sums orders and payments by customer. I have three tables; cust, orders and pay and they are linked by custid. All customers have at least one order and one payment.
I get incorrect results with the following code:

SELECT Cust.custid, Cust.custname, sum(orders.amt), sum(pay.payamt);
FROM cust ;
Inner Join orders on Cust.custid = Orders.custid ;
Inner Join pay on cust.custid = pay.custid;
GROUP BY Cust.custid


The following, however, does work correctly, but I want it in one view.

SELECT Cust.custid, Cust.custname, sum(orders.amt);
FROM cust ;
Inner Join orders on Cust.custid = Orders.custid ;
GROUP BY Cust.custid;
into Cursor temp

Select temp.*, sum(pay.payamt);
From Temp;
Inner Join pay on Temp.custid=pay.custid;
Group by Temp.custid

Can anyone explain what is going on and perhaps provide some help?
Thanks
Jay
Next
Reply
Map
View

Click here to load this message in the networking platform