Results 1 to 3 of 3
  1. #1
    Monty_99 is offline Novice
    Windows 10 Access 2019
    Join Date
    Sep 2022
    Posts
    1

    Querying distinct for multiple values

    I suspect this is an easy question, but it has me stumped.



    I use Access to track meetings with each customer. I have two tables:

    tblContact (ID, Contact, Company)
    tblMeetings (ID, ContactID, MtgDate)

    I would like a query that says how many times I have met with people from each company, where multiple meetings on the same day with a company count as 1. So if I meet with three people from Company AAA on September 1, that only counts as one meeting. What am I doing wrong with my query?


    SELECT DISTINCTROW tblContacts.Company, Count(*)
    FROM tblMeetings INNER JOIN tblContacts ON tblMeetings.ContactID = tblContacts.ID
    GROUP BY tblContacts.Company;


    This is giving me multiples for each day. What am I doing wrong?

  2. #2
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    229
    Try
    Code:
    SELECT Company, Count(MtgDate) AS Meetings 
    FROM (SELECT DISTINCT Company, MtgDate FROM tblContacts INNER JOIN tblMeetings ON tblContacts.ID = tblMeetings.ContactID)
    GROUP BY Company;

  3. #3
    cartwright is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2020
    Posts
    3
    Quote Originally Posted by xps35 View Post
    Try
    Code:
    SELECT Company, Count(MtgDate) AS Meetings 
    FROM (SELECT DISTINCT Company, MtgDate FROM tblContacts INNER JOIN tblMeetings ON tblContacts.ID = tblMeetings.ContactID)
    GROUP BY Company;
    Perfect. Thank you!

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

Similar Threads

  1. Replies: 11
    Last Post: 01-29-2022, 04:40 PM
  2. Replies: 3
    Last Post: 10-30-2016, 05:50 AM
  3. Replies: 12
    Last Post: 01-13-2015, 10:32 AM
  4. Replies: 1
    Last Post: 04-30-2014, 01:05 AM
  5. Replies: 1
    Last Post: 03-28-2013, 11:10 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