Results 1 to 3 of 3
  1. #1
    DatabaseWoes is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Jul 2017
    Posts
    4

    Matching records in sequence

    Does anyone know of a technique to match records in a query in sequential order?

    For example, given two recordsets:

    |Group|Number
    |A |700
    |A |701
    |A |790
    |A |799
    |B |604


    |B |605
    |C |800
    |C |801
    |C |802
    |C |803


    |Group|Name
    |A |Adam
    |A |Bill
    |A |Carl
    |B |Dave
    |C |Evan
    |C |Fred
    |C |Greg
    |C |Hugh
    |B |Ira

    Is there a query technique that will take the first name, match the lowest available number in its group, go to the next name, match the NEXT lowest number available in the group, and so on?

    The result might look like this:

    |Number|Name
    |700 |Adam
    |701 |Bill
    |790 |Carl
    |604 |Dave
    |800 |Evan
    |801 |Fred
    |802 |Greg
    |803 |Hugh
    |605 |Ira

    Thanks.

  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,900
    Consider:

    Query: NamesSeq
    SELECT Names.Group, Names.Name, DCount("*","Names","Group='" & [Group] & "' AND [Name]<'" & [Name] & "'")+1 AS NameSeq
    FROM [Names];

    Query: NumbersSeq
    SELECT Numbers.Group, Numbers.Number, DCount("*","Numbers","Group='" & [Group] & "' AND Number<" & [Number])+1 AS NumSeq
    FROM Numbers;

    Query:
    SELECT NamesSeq.Group, NamesSeq.Name, NumbersSeq.Number
    FROM NumbersSeq INNER JOIN NamesSeq ON (NumbersSeq.NumSeq = NamesSeq.NameSeq) AND (NumbersSeq.Group = NamesSeq.Group);
    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
    DatabaseWoes is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Jul 2017
    Posts
    4
    Quote Originally Posted by June7 View Post
    Consider:

    Query: NamesSeq
    SELECT Names.Group, Names.Name, DCount("*","Names","Group='" & [Group] & "' AND [Name]<'" & [Name] & "'")+1 AS NameSeq
    FROM [Names];

    Query: NumbersSeq
    SELECT Numbers.Group, Numbers.Number, DCount("*","Numbers","Group='" & [Group] & "' AND Number<" & [Number])+1 AS NumSeq
    FROM Numbers;

    Query:
    SELECT NamesSeq.Group, NamesSeq.Name, NumbersSeq.Number
    FROM NumbersSeq INNER JOIN NamesSeq ON (NumbersSeq.NumSeq = NamesSeq.NameSeq) AND (NumbersSeq.Group = NamesSeq.Group);
    Considered, tested, found to be brilliant.

    Thanks so much!!

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

Similar Threads

  1. Replies: 6
    Last Post: 03-17-2017, 10:28 PM
  2. subform records notdisplayed in date sequence
    By stan@fangandthegang.com in forum Forms
    Replies: 3
    Last Post: 07-05-2014, 06:08 AM
  3. Replies: 3
    Last Post: 07-29-2012, 04:37 PM
  4. Replies: 1
    Last Post: 10-24-2011, 08:01 AM
  5. Replies: 1
    Last Post: 08-11-2011, 11:33 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