Beauty. Worked like a charm. I can promise I would NEVER have gotten that syntax nailed on my own. Thanks so much!
Main Topics
Browse All TopicsI am writing a number of queries against a record set with somewhat complex WHERE conditions, such that when all queries are written, every record should exist in one (and only one) of the various queries. As a cross-check against a master data list, I would like to create a "dashboard" query so that I can (hopefully somewhat simply) copy and paste my various queries into the "dashboard" query, whose only job is to give me the record (row) count of each of the queries as a column in my dashboard query.
I am not very experienced in writing sub-queries, and am not able to come up with the syntax to do this. In a sort of pseudo-code form, what I am hoping for is:
SELECT
COUNT of rows in (My Complex Query 1 Here) AS Report_1_Count,
COUNT of rows in (My Complex Query 2 Here) AS Report_2_Count,
COUNT of rows in (My Complex Query 3 Here) AS Report_3_Count
yeah, I know that's nowhere close to SQL code but if I could write it out in proper SQL I'd probably not be posting here :-)
A bonus would be to be able to get the sum total of all the rows in each of the subqueries as a sort of grand total, but really what I need to do right now is just get the count of each of the subqueries. Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: lwadwellPosted on 2009-11-03 at 12:48:40ID: 25733425
Hi propertytax,
I suppose one way would be
SELECT r1_count, r2_count, r3_count, r1_count + r2_count + r3_count as tot_count
FROM
(select count(*) as r1_count from (your Complex Query 1 Here) as r1) as r1v,
(select count(*) as r2_count from (your Complex Query 2 Here) as r2) as r2v,
(select count(*) as r3_count from (your Complex Query 3 Here) as r3) as r3v
lwadwell