Ollie Sharratt
Ollie Sharratt

Reputation: 95

Query Combining Records Based on Columns

I am creating an access query to give a live view of the quantities of parts in a database, however I am not sure where to start with it. Lets say I have the following table, there are many more columns but these are the important three:

| PartNumber | Description   | Quantity |
| 12345      | a part        | 4        |
| 12345      | a part        | 3        |
| 54321      | another part  | 1        |
| 24513      | an extra part | 6        |

I would like the query to produce;

| PartNumber | Description   | Quantity |
| 12345      | a part        | 7        |
| 54321      | another part  | 1        |
| 24513      | an extra part | 6        |

So it then tells me how many of each part there is in the database.

Upvotes: 0

Views: 30

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520968

A basic GROUP BY aggregation query should work here:

SELECT PartNumber, Description, SUM(Quantity) AS Quantity
FROM yourTable
GROUP BY PartNumber, Description;

Upvotes: 1

Related Questions