Results 1 to 5 of 5
  1. #1
    jazzin is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    14

    Using GROUP BY to group the count of multiple tables

    I have figured out how to get the total # of rows for each of my tables, however it creates an infinite # of rows that list the totals of each table. How can I group all these rows together so I have just one row with the total for each table in it?

    Here's what I have so far

    SELECT (SELECT Count([3_0_addr].ADDRESS) AS 3_0_NUMOFRECS
    FROM 3_0_addr) AS 3_0_NUMOFRECS, (SELECT Count([3_2_addr].ADDRESS) AS 3_2_NUMOFRECS
    FROM 3_2_addr) AS 3_2_NUMOFRECS, (SELECT Count([3_4_addr].ADDRESS) AS 3_4_NUMOFRECS
    FROM 3_4_addr) AS 3_4_NUMOFRECS, (SELECT Count([3_6_addr].ADDRESS) AS 3_6_NUMOFRECS
    FROM 3_6_addr) AS 3_6_NUMOFRECS, (SELECT Count([3_8_addr].ADDRESS) AS 3_8_NUMOFRECS
    FROM 3_8_addr) AS 3_8_NUMOFRECS, (SELECT Count([4_0_addr].ADDRESS) AS 4_0_NUMOFRECS
    FROM 4_0_addr) AS 4_0_NUMOFRECS, (SELECT Count([4_2_addr].ADDRESS) AS 4_2_NUMOFRECS
    FROM 4_2_addr) AS 4_2_NUMOFRECS, (SELECT Count([4_4_addr].ADDRESS) AS 4_4_NUMOFRECS
    FROM 4_4_addr) AS 4_4_NUMOFRECS, (SELECT Count([4_6_addr].ADDRESS) AS 4_6_NUMOFRECS
    FROM 4_6_addr) AS 4_6_NUMOFRECS, (SELECT Count([4_8_addr].ADDRESS) AS 4_8_NUMOFRECS
    FROM 4_8_addr) AS 4_8_NUMOFRECS, (SELECT Count([5_0_addr].ADDRESS) AS 5_0_NUMOFRECS
    FROM 5_0_addr) AS 5_0_NUMOFRECS, (SELECT Count([5_2_addr].ADDRESS) AS 5_2_NUMOFRECS
    FROM 5_2_addr) AS 5_2_NUMOFRECS, (SELECT Count([5_4_addr].ADDRESS) AS 5_4_NUMOFRECS
    FROM 5_4_addr) AS 5_4_NUMOFRECS, (SELECT Count([5_6_addr].ADDRESS) AS 5_6_NUMOFRECS
    FROM 5_6_addr) AS 5_6_NUMOFRECS
    FROM 3_0_addr, 3_2_addr, 3_4_addr, 3_6_addr, 3_8_addr, 4_0_addr, 4_2_addr, 4_4_addr, 4_8_addr, 5_0_addr, 5_2_addr, 5_4_addr, 5_6_addr, 4_6_addr;


    Any help on how to group this would be appreciated

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    How many tables are you doing this with (28)? Is there a common ID value that they can be joined on in query? If not, do a UNION query then use that query in a CROSSTAB.

    There is no wizard or designer for UNION query, must type (or copy/paste) into SQL View window of query builder, limit of 50 lines.

    SELECT Count(ADDRESS) AS NumOfRecs, "3_0" AS Source FROM 3_0_addr
    UNION SELECT Count(ADDRESS), "3_2" FROM 3_2_addr
    ...
    UNION SELECT Count(ADDRESS), "4_6" FROM 4_6_addr;


    Alternative to UNION then CROSSTAB is DCount() domain aggregate function.

    SELECT DCount("Address", "3_0_addr") AS 3_0_NumOfRecs, ..., DCount("Address", "4_6_addr") AS 4_6_NumOfRecs FROM [use name of any table in db];
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    jazzin is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    14
    I have 14 tables. I thought about creating a relationship btw tables but I really don't want to take attributes from each table and combine them. All I want to do is get a total count of the number of records in wach table, which I have in the above code but it list an infinite list of numbers in each column. What I need is to group the totals together so they are all on one row and not infinite rows.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    One of the two suggested methods should get you there.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    jazzin is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    14
    Hey it worked! Thanks a bunch!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. COUNT Group Count Records COUNT FUNCTION
    By PMCOFFEY in forum Access
    Replies: 9
    Last Post: 11-09-2012, 09:40 PM
  2. Group by two columns and count
    By bas85 in forum Queries
    Replies: 5
    Last Post: 10-03-2012, 10:09 AM
  3. First Group, Second count, and third sum
    By hoachen in forum Access
    Replies: 2
    Last Post: 07-30-2012, 06:03 PM
  4. GROUP and COUNT?
    By TheMoodyFiles in forum Queries
    Replies: 2
    Last Post: 02-10-2011, 05:50 PM
  5. SQL Count and Group By
    By Tyork in forum Programming
    Replies: 11
    Last Post: 01-24-2011, 09:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums