This SQL does the basics of what you ask:
SELECT [table 1].category, Sum(Nz([Table 1].[amount])) AS
customer_demanded, Sum(Nz([Table 2].[amount])) AS supplier_demanded
FROM [table 1] INNER JOIN [table 2] ON [table 1].category = [table
2].category
GROUP BY [table 1].category;
However this doesn't achieve exactly what you want, because it only
gives a result for categories that appear in both tables. To get all
results from one table (e.g. [Table 1]) and matching results from Table
2, use this instead:
SELECT [table 1].category, Sum(Nz([Table 1].[amount])) AS
customer_demanded, Sum(Nz([Table 2].[amount])) AS supplier_demanded
FROM [table 1] LEFT JOIN [table 2] ON [table 1].category = [table
2].category
GROUP BY [table 1].category;
Ideally, you actually have a separate table that contains ALL
categories, then you could make sure all categories had an amount
against them, eg:
SELECT Categories.category, Sum(Nz([Table 1].[amount])) AS
customer_demanded, Sum(Nz([Table 2].[amount])) AS supplier_demanded
FROM (Categories LEFT JOIN [Table 1] ON Categories.category = [Table
1].category) LEFT JOIN [Table 2] ON Categories.category = [Table
2].category
GROUP BY Categories.category;
Good luck!
------------
LoopyNZ
------------
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!