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

Rich Goldberg 141 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?

Access
Access
A family of Microsoft relational database management systems designed for ease of use.
390 questions
Office Management
Office Management
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Management: The act or process of organizing, handling, directing or controlling something.
2,147 questions
{count} votes

Accepted answer
  1. Michael Taylor 54,316 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 Answers by the question author, which helps users to know the answer solved the author's problem.