Results 1 to 4 of 4
  1. #1
    MatthewR is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    118

    Counting Distinct Values - People Who Appear in Related Table

    I think this is pretty basic, but I can't figure it out. I want to count the number of people from a table, tblVictimsPerps, that appear in a related table, tblRelationships, where a few criteria are met. If a person appears multiple times, my current query counts each time they appear. But, I only want to count them once. I tried changing the query's "Unique Values" property to Yes, but that did not work. What should I do? Here is the SQL:

    SELECT tblInjunctionHistory.ActiveOrExpiredInjunction, Count(tblVictimsPerps.PersonID) AS CountOfPersonID
    FROM ((tblFatalIncidents INNER JOIN tblVictimsPerps ON tblFatalIncidents.[Fatal Incident #] = tblVictimsPerps.Incident) LEFT JOIN tblInjunctionHistory ON tblVictimsPerps.PersonID = tblInjunctionHistory.Person) INNER JOIN tblRelationships ON tblVictimsPerps.PersonID = tblRelationships.Perpetrator


    WHERE (((tblVictimsPerps.VictimOrPerp)="Perpetrator") AND ((tblFatalIncidents.DataComplete)=True) AND ((tblRelationships.Intimate)=1))
    GROUP BY tblInjunctionHistory.ActiveOrExpiredInjunction;



    Click image for larger version. 

Name:	Injunction Status Query Snapshot.png 
Views:	9 
Size:	33.9 KB 
ID:	23000

    Thanks in advance for your help!

    Matthew

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Build a DISTINCT query that returns each person only once.

    Then reference that query in another query to do the count.


    Did you try deleting the second attachment with Manage Attachments in the Advanced post editor?
    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
    MatthewR is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    118
    Thanks very much, June. Let me give that a try, and I'll let you know if I have any issues.

    Also, thanks for the tip on the extra attachment. I deleted it with the Advanced post editor.

  4. #4
    MatthewR is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2015
    Posts
    118
    Woo hoo! It worked! Thanks so much.

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

Similar Threads

  1. Adding people to case table from people table.
    By fuonge in forum Database Design
    Replies: 2
    Last Post: 09-22-2015, 11:53 AM
  2. Replies: 3
    Last Post: 08-09-2015, 06:57 PM
  3. Replies: 2
    Last Post: 12-05-2011, 04:53 AM
  4. help counting distinct values
    By joo-joo-man in forum Queries
    Replies: 2
    Last Post: 10-17-2010, 05:18 AM
  5. Counting distinct id's
    By jqljql in forum Access
    Replies: 1
    Last Post: 09-01-2006, 07:28 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