Combining results with a Query of Queries - NOT QUITE THERE!!!
I have included a small sample of my database, specifically the four tables I am trying to work with in the hopes that someone can steer me down the right path. Here are the four tables and the bottom is a visual desciption of what I am trying to achieve;
| ORDERS | SALES CALLS | |||||||||
| ID | SaleDate | TerritoryManager | UserID | SaleDate | TerritoryManager | ID | UserID | |||
| 426 | 01-Oct-09 | Mike B | 10112 | 10/1/2009 | Mike B | 253 | 10112 | |||
| 427 | 01-Oct-09 | Russ C | 10115 | 10/1/2009 | Mike B | 254 | 10112 | |||
| 430 | 01-Oct-09 | Jerry W | 10145 | 10/1/2009 | Mike B | 255 | 10112 | |||
| 432 | 01-Oct-09 | Ron H | 10118 | 10/1/2009 | Mike B | 256 | 10112 | |||
| 433 | 01-Oct-09 | Ron H | 10118 | 10/1/2009 | Ron H | 257 | 10118 | |||
| 10/1/2009 | Ron H | 258 | 10118 | |||||||
| PRODUCTS ORDERED | 10/1/2009 | Ron H | 260 | 10118 | ||||||
| OrderID | Quantity | NewExisting | UserID | 10/1/2009 | Russ C | 261 | 10115 | |||
| 426 | 12 | 0 | 10112 | 10/1/2009 | Mike B | 267 | 10112 | |||
| 427 | 2 | 0 | 10115 | 10/1/2009 | Mike B | 268 | 10112 | |||
| 427 | 3 | 1 | 10115 | |||||||
| 430 | 1 | 0 | 10145 | USERS | ||||||
| 430 | 1 | 0 | 10145 | TerritoryManager | Zone | UserID | ||||
| 432 | 1 | 0 | 10118 | Mike B | Central | 10112 | ||||
| 432 | 1 | 0 | 10118 | Russ C | Central | 10115 | ||||
| 432 | 1 | 1 | 10118 | Jerry W | Central | 10145 | ||||
| 432 | 1 | 1 | 10118 | Ron H | Central | 10118 | ||||
| 433 | 2 | 1 | 10120 | Don M | Central | 10120 | ||||
| Central Zone | Ttl Calls | Ttl Orders | Ttl Items | Ttl New Items | ||||||
| Mike B | 5 | 1 | 12 | 1 | ||||||
| Russ C | 1 | 1 | 5 | |||||||
| Jerry W | 1 | 2 | ||||||||
| Ron H | 3 | 2 | 6 | 3 | ||||||
I have tried to achieve this result in many ways to no avail. If I try to combine PRODUCTS ORDERED with ORDERS I get an erroneous count. I finally resigned myself to getting all the info I needed with separate queries and then trying to combine them with a query of queries. This worked fine until the last query of queries which timed out with no results. I am a newbie and would appreciate any constructive help with this. I am including my queries below as well;
<cfquery name="qGetOrders" datasource="manna_premier">
SELECT Count(Orders.ID) AS CountOfID,
Orders.UserID AS Orders_UserID,
Users.UserID AS Users_UserID,
Users.TMName
FROM Users INNER JOIN Orders ON Users.[UserID] = Orders.[UserID]
GROUP BY Orders.UserID, Users.UserID, Users.TMName;
</cfquery>
<cfquery name="qGetSalesCalls" datasource="manna_premier">
SELECT Count(Sales_Calls.ID) AS CountOfID,
Users.UserID AS Users_UserID,
Users.TMName,
Sales_Calls.UserID AS Sales_Calls_UserID
FROM Users INNER JOIN Sales_Calls ON Users.[UserID] = Sales_Calls.[UserID]
GROUP BY Sales_Calls.UserID, Users.UserID, Users.TMName;
</cfquery>
<cfquery name="qGetProducts" datasource="manna_premier">
SELECT Count(ProductOrders.OrderID) AS CountOfOrderID,
Sum(ProductOrders.Quantity) AS SumOfQuantity,
Sum(ProductOrders.NewExisting) AS SumOfNewExisting,
ProductOrders.UserID
FROM Orders INNER JOIN ProductOrders ON Orders.[ID] = ProductOrders.[OrderID]
GROUP BY ProductOrders.UserID;
</cfquery>
<cfquery name="qqCombOrd_Prod" dbtype="query">
SELECT *
FROM qGetOrders, qGetProducts
</cfquery>
<cfquery name="qqCombOrd_ProdtoSales" dbtype="query">
SELECT *
FROM qqCombOrd_Prod, qGetSalesCalls
</cfquery>
PLEASE HELP!!! I'm about to go scouting for bridges to leap from!
