Multiple Unrelated Queries into one

Moxioron

Active Member
Joined
Mar 17, 2008
Messages
436
Office Version
  1. 2019
Hello.

This might be a no brainer, but I am stumped.

My goal is to have one query that counts and sums the amount fields of other, unlrelated queries. This query will be used a summary.

I tried the normal Count and Sum route and I tried to build expressions, but no can do. It counts and sums the entire table that the queries are tied to.

Any thoughts?

Here is my SQL with two of the queries.

SELECT Count([qry_Exceptions - By Queue Manual Adds (Detail).Amount]) AS Expr2, Sum([qry_Exceptions - By Queue Manual Adds (Detail).Amount]) AS Expr1, Count([qry_Exceptions - By Queue PAID WO NSF or SS (Detail).Amount]) AS Expr3, Sum([qry_Exceptions - By Queue PAID WO NSF or SS (Detail).Amount]) AS Expr4
FROM [qry_Exceptions - By Queue Manual Adds (Detail)], [qry_Exceptions - By Queue PAID WO NSF or SS (Detail)];
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
My goal is to have one query that counts and sums the amount fields of other, unlrelated queries.
If they are unrelated, you don't want to do the SUM/COUNTs n the same query. You typically never want to have unrelated data sources in the same query unless you are purposely trying to create a Cartesian product (http://www.dba-oracle.com/t_garmany_9_sql_cross_join.htm).

You should do a separate query for each of your unrelated data sources. If you are trying to summarize the results, there are various ways to do this (Union queries, update back to a table with Update or Append Queries, use subreports, etc).
 
Upvote 0
Thanks for the response.

That is what I thought (creating additional individual queries that count and sum then joining those queries).
 
Upvote 0
Yes, if you end up with single record queries (for Sums and Counts), then if you do a query with no join on those, it will only create a single record (Cartesian Product of 1 times 1 still equals one).
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,611
Members
452,931
Latest member
The Monk

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top