Results 1 to 2 of 2
  1. #1
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283

    Subquery Help

    Hello,



    I'm trying to figure out the best solution to this problem. I'm trying to find the total count of emails, oldest date in folder, and number of emails with the oldest date per folder that I have linked from Microsoft Outlook. I have about 20 folder I have linked to in Microsoft Access. I have figured out how to get the oldest date and the count of total emails per folder. But I need to get the number of emails with the oldest date per folder. I don't know if I can do this with all one query since I would have 2 count functions. And I can't think of the best way for a subquery with this many tables. I would have so many queries. Your help would be much appreciated.

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,891
    Maybe like:

    SELECT "T1" AS Source, Max(datefield) AS MaxDate, Count(*) As TotalEmails, (SELECT Count(*) AS CM FROM table1 WHERE datefield=DMax("datefield","table1")) AS CntMax FROM table1 GROUP BY "T1"
    UNION SELECT "T2", Max(datefield), Count(*), (SELECT Count(*) AS CM FROM table2 WHERE datefield=DMax("datefield","table2")) FROM table2 GROUP BY "T2";

    or

    SELECT "T1" AS Source, Max(datefield) AS MaxDate, Count(*) As TotalEmails, (SELECT Count(*) AS CM FROM table1 WHERE datefield=(SELECT Max(datefield) FROM table1)) AS CntMax FROM table1 GROUP BY "T1"
    UNION SELECT "T2", Max(datefield), Count(*), (SELECT Count(*) AS CM FROM table2 WHERE datefield=(SELECT Max(datefield) FROM table2)) FROM table2 GROUP BY "T2";
    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.

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

Similar Threads

  1. Subquery Help
    By MTSPEER in forum Queries
    Replies: 1
    Last Post: 06-05-2017, 09:54 AM
  2. Subquery
    By Daryl2106 in forum Access
    Replies: 20
    Last Post: 01-13-2013, 07:21 AM
  3. Subquery
    By tomclavil in forum Queries
    Replies: 3
    Last Post: 02-27-2012, 03:05 AM
  4. TOP subquery
    By helpaccess in forum Queries
    Replies: 5
    Last Post: 08-30-2011, 10:28 AM
  5. Subquery sum?
    By anemoskkk in forum Access
    Replies: 0
    Last Post: 04-29-2011, 12:36 PM

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