Others

How to Create an Access SQL Query for Total Sales by Product Type

Rana GarciaRana Garcia Oct 26, 2026 868 views

Question details

The user needs to write an SQL query in Microsoft Access to join transaction and product tables, calculate quarter-one total sales by product type, filter for totals of at least 100, and sort in descending order.

How to Create an Access SQL Query for Total Sales by Product Type
Product
Microsoft Access
Device & OS
not provided
Scenario
Writing a custom SQL query to generate a quarterly sales report grouped by product category.
Observed behavior
The user requires the exact SQL syntax to properly join tables, aggregate sales data using SUM, apply a minimum threshold filter, and sort the calculated results.
Before you start

Verify that your database contains the tables tblTransactions and tblProducts, and note the exact field names used for the sales volume, product type, and primary keys before constructing the query.

Solution 1Recommended

Write the SQL Query using INNER JOIN and HAVING

This method guides you through constructing the SELECT statement to join the required tables, aggregate the total sales, and properly filter the grouped totals.

In Microsoft Access SQL, combining data from two tables requires an INNER JOIN. When calculating aggregated data like total sales volume per product, you must use the GROUP BY clause. Crucially, any filters applied to these aggregated totals (such as a minimum volume of 100) must be placed in the HAVING clause rather than the WHERE clause.

1
Open Query Design

Launch Microsoft Access, open your database, navigate to the Create tab on the ribbon, and click Query Design.

2
Switch to SQL View

Close the Show Table dialog box that appears. Right-click the query tab and select SQL View from the context menu.

3
Write the SELECT and JOIN clauses

Type 'SELECT tblProducts.ProductType, SUM(tblTransactions.SalesVolume) AS HighSalesVolume FROM tblTransactions INNER JOIN tblProducts ON tblTransactions.ProductID = tblProducts.ProductID' to select the fields and join the tables.

4
Add GROUP BY and HAVING clauses

Add 'GROUP BY tblProducts.ProductType HAVING SUM(tblTransactions.SalesVolume) >= 100' to group the results and filter for totals of at least 100.

5
Add the ORDER BY clause

Finally, append 'ORDER BY SUM(tblTransactions.SalesVolume) DESC;' to the query to sort the filtered results in descending order.

6
Run the Query

Click the Run button (red exclamation mark) on the Query Design tab to execute the SQL statement and view the resulting datasheet.

Write the SQL Query using INNER JOIN and HAVING
HAVING vs. WHERE: The WHERE clause filters individual records before they are grouped, while the HAVING clause filters the aggregated results after grouping. You cannot use aggregate functions like SUM in a WHERE clause.
Free Microsoft Office alternative

Analyze Business Data with WPS Spreadsheet

While Microsoft Access is a powerful tool for relational databases, you can handle most sales tracking, filtering, and data aggregation efficiently using WPS Spreadsheet. WPS Office offers a free, lightweight, and highly compatible alternative to Microsoft Office for your daily data management and analysis.

  1. 1. Export Access Data: In Microsoft Access, right-click your raw data table or query, select Export, and choose Excel to save the file.
  2. 2. Open in WPS Spreadsheet: Launch WPS Office and open the exported .xlsx file seamlessly in WPS Spreadsheet.
  3. 3. Create a PivotTable: Highlight your data, navigate to the Insert tab, and click PivotTable to quickly group your products and calculate total sales volume without any code.
Highly compatible with Microsoft Excel (.xlsx) formats, ensuring seamless data migration and sharing.Built-in PivotTable features allow you to group and sum sales data by product type without writing complex SQL queries.Includes comprehensive, lightweight alternatives for Word, Excel, and PowerPoint in a single free application.
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get an error when using WHERE to filter total sales?

The WHERE clause is evaluated before data is grouped and aggregated. Because total sales are calculated using the SUM function, you must use the HAVING clause, which applies conditions to the data after the GROUP BY operation.

How can I filter the query specifically for quarter-one transactions?

To filter raw records before grouping, add a WHERE clause before the GROUP BY statement. For example, include 'WHERE tblTransactions.TransactionDate BETWEEN #01/01/2023# AND #03/31/2023#' to limit the data to the first quarter.

Can I use the alias in the HAVING or ORDER BY clauses?

In Microsoft Access SQL, you typically cannot use a newly created column alias (like HighSalesVolume) in the HAVING clause; you must repeat the aggregate function (e.g., HAVING SUM(SalesVolume) >= 100). However, some database engines do allow the alias in the ORDER BY clause.

How do I write an INNER JOIN for more than two tables in Access?

Access requires parentheses when joining more than two tables. The syntax nests the joins, for example: 'FROM (TableA INNER JOIN TableB ON TableA.ID = TableB.ID) INNER JOIN TableC ON TableB.ID = TableC.ID'.