Share via

Best way to sort and reduce data in an Access MDB table

Rich Goldberg 166 Reputation points
2024-07-29T02:26:24.69+00:00

Looking for some advice on handling a table. I’ve got an Access mdb database. The VB program that drives it  puts data into two columns of a table, and for each row it puts a numeric reason code in the third column. The data pairs in the first two columns may be duplicated many times, but each occurrence will have a unique reason code. I need to end up with a single row for each data pair (sorted by column A/column B), with only the lowest reason code remaining.

 

For example, the program may write the data in the following order:

Column A Column B`` ``Reason Code

aaa        bbb        4

aaa        bbb        2

bbb        ccc        1

bbb        ccc        3

aaa        bbb        0

 The result I need is:

Column A Column B`` ``Reason Code

aaa        bbb        0

bbb        ccc        1

Can the table be defined so that the table automatically ends up in the order I need? Or do I need to populate the table first, then use a query to sort the rows and eliminate the duplicates?

Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Microsoft 365 and Office | Access | For business | Windows
{count} votes

Answer accepted by question author
  1. Michael Taylor 61,191 Reputation points
    2024-07-29T02:44:53.64+00:00

    You need to store the data otherwise you'll lose it. You'll use a query to group the data to what you want.

    SELECT ColumnA, ColumnB, MIN(Reason Code)
    FROM table1
    GROUP BY ColumnA, ColumnB
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.