Kind of Duplicate problem

chazup

New member
Local time
Today, 00:38
Joined
Aug 13, 2009
Messages
8
I have two queries pulling data and manipulating it based on two separate tables. The Queries are each grouped by month and year and so info for the last 24 months. I am making a 3rd query that takes the data from each query and manipulates that. However when i do this it multiplies the entire table by a single field, instead of just two fields. Heres an example, (i know that made little sense)
Query 1:
Year, Month, Total Billed, Total Recieved
2008, jan, 100, 90
2009, may, 212, 118

Query 2:
Year, Month, TPS, TV, AP/H
2008, jan, 50, 4, 3.5
2009, may, 60, 5, 3.2

All the info from these queries are taken from seprate, but related tables.
This is basicly what my sql code looks like for the 3rd table and what it generates.

Code:
Select  [AP/H], 
[Query 2].Year, 
[Query 2].month
[Total Billed]/[TV] AS [B/V]
FROM [Query 1], [Query 2]
GROUP BY [Year], [Month]

Query 3
Year, Month, AP/H, B/V
2008, Jan, 3.5, 25
2009, may, 3.2, 20
2008, Jan, 3.5, 53
2009, may 3.2 42.3

It's basically dividing each month from query 2 twice, once for each month of Query 1. Hence the 4 results. How would i be able to get it to just calculate like months.

Thanks
 
Without a join between the tables, you'll get a Cartesian product. You need to join them on the appropriate field(s).
 
I related the tables based on date and I tried the join going both ways it still doesn't work
 
Can you post a sample of the db? From the look of it, I'd expect joins on both the year and month fields (neither of which are good field names, as they are reserved words).
 
I figured it our, while the tables had joins the queries did not, thanks a ton for your help
 
Sorry, I should have mentioned that they had to be in the query. Glad you got it sorted out.
 

Users who are viewing this thread

Back
Top Bottom