Results 1 to 7 of 7
  1. #1
    MikeCt is offline Advanced Beginner
    Windows 10 Access 2021
    Join Date
    Jan 2025
    Posts
    35

    Query for repeat pairings and give count if found

    I have groups of members that meet once a week.
    Every week the members are in different groups with different members
    Each week all members are recorded as to who they were grouped together with in a table "GroupData"



    How can I check if a member has been grouped together in a previous week and if so, how many times

    In the database attached I know member #30 has been grouped together with member #175, twice
    (Its possible other members may have repeats also, in the example attached)

    Thanks for any help
    Attached Files Attached Files

  2. #2
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    565
    Oh, previous week... I think I skipped that part.

    here's the groupings stuff:
    xjGroupings (Cross join):

    Code:
    SELECT GroupData.MemberID, GroupData_1.MemberID AS GroupedWithMember
    FROM GroupData AS GroupData_1 INNER JOIN GroupData ON (GroupData.Group = GroupData_1.Group) AND (GroupData_1.EventDate = GroupData.EventDate);
    then query and summarize that:
    Code:
    SELECT xjGroupings.MemberID, xjGroupings.GroupedWithMember, Count(xjGroupings.MemberID) AS CountOfMemberID
    FROM xjGroupings
    GROUP BY xjGroupings.MemberID, xjGroupings.GroupedWithMember
    HAVING (((xjGroupings.MemberID)<>[xjGroupings].[GroupedWithMember]) AND ((Count(xjGroupings.MemberID))>1));

  3. #3
    MikeCt is offline Advanced Beginner
    Windows 10 Access 2021
    Join Date
    Jan 2025
    Posts
    35
    Thanks this is exactly what I was looking for.

    I have a question since I'm trying to learn as much from this as possible. With what you have given me it is easy to loop thru the list and get any results I need. Is it faster to query for results on one particular member at a time and is that possible. This query returns a list of 20 items. As the groups meets during the year this query will create a list maybe up to a few hundred entries. I know that's not much but I'm trying to learn to do what's best.

    Thanks for your quick response
    Mike

  4. #4
    madpiet is offline Expert
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    565
    Quote Originally Posted by MikeCt View Post
    Thanks this is exactly what I was looking for.

    I have a question since I'm trying to learn as much from this as possible. With what you have given me it is easy to loop thru the list and get any results I need. Is it faster to query for results on one particular member at a time and is that possible. This query returns a list of 20 items. As the groups meets during the year this query will create a list maybe up to a few hundred entries. I know that's not much but I'm trying to learn to do what's best.

    Thanks for your quick response
    Mike
    What do you mean by "looping"? Cursors/recordsets are usually a dirty word in SQL. Well, it's a tool of last resort. Only use if if you absolutely need to because (1) it doesn't scale, (2) it can be crazy slow.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    Is this the same question as your other thread a couple of months ago?
    https://www.accessforums.net/showthread.php?t=90596

  6. #6
    MikeCt is offline Advanced Beginner
    Windows 10 Access 2021
    Join Date
    Jan 2025
    Posts
    35
    By looping I mean going thru the list from top to bottom looking for a specific ID
    This is why I was asking if I could use something in your Query like "WHERE MemberID = 30" retrieving only one item
    I'm going to play with what you sent me and learn from it what I can from it.
    Thanks for not giving me a hard time, I'm just trying to learn how to do thing right.
    Thanks again
    Mike

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    "Right" is what solves issue to your satisfaction.

    Yes, building a WHERE clause in query is one way. Can hard-code the parameter or make it dynamic.
    Or use filter tools on ribbon or right click menu or quick search/sort from table/query headers.

    I don't use search parameters in queries if I can help it. I use VBA to build criteria and apply to form or report.

    Are you the only user of this db (I assume there is more to your db than the one table provided)?
    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. Count Matrix Repeat
    By lukets123 in forum Access
    Replies: 1
    Last Post: 03-24-2021, 08:56 AM
  2. Repeat Prompt Count
    By afa in forum Access
    Replies: 2
    Last Post: 02-12-2016, 03:21 PM
  3. Replies: 7
    Last Post: 12-17-2015, 04:36 PM
  4. Replies: 30
    Last Post: 08-15-2012, 02:25 PM
  5. Replies: 7
    Last Post: 08-15-2011, 05:35 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