How to Generate Sequential Row Numbers in Microsoft Access SQL
Question details
The user needs to generate sequential row numbers for records in Microsoft Access using SQL, specifically handling gaps in transaction dates.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Creating sequential IDs for sorting or querying data when transaction dates have irregular gaps like weekends or holidays.
- Observed behavior
- Access lacks a built-in ROW_NUMBER() function in its SQL dialect, requiring workarounds like self-joins to generate sequential numbers.
Ensure your Microsoft Access database is well under the 2 GB size limit and that your target table has a primary key (such as an AutoNumber field) to help uniquely identify records and resolve ties.
Use a Self-Join with Count to Generate Row Numbers
Use a self-join query to count how many records have a date less than or equal to the current record's date, generating a sequential row number.
Since Microsoft Access SQL does not support the ROW_NUMBER() window function found in T-SQL, you must use a correlated subquery or a self-join to calculate row numbers dynamically.
This method counts the number of previous records based on your transaction date. If dates can be duplicated, a secondary unique identifier is necessary to prevent tied rankings.
Open your Access database, navigate to the 'Create' tab on the ribbon, and click 'Query Design'. Close the 'Show Table' dialog.
Click the 'View' button in the top-left corner and select 'SQL View' from the dropdown menu to manually enter your query.
Enter a SELECT statement that uses a subquery to count records. For example: `SELECT T1.TransactionDate, (SELECT COUNT(*) FROM YourTable AS T2 WHERE T2.TransactionDate <= T1.TransactionDate) AS RowNum FROM YourTable AS T1;`
To resolve ties if dates repeat, include a unique AutoNumber field (e.g., ID) in the subquery logic: `WHERE T2.TransactionDate < T1.TransactionDate OR (T2.TransactionDate = T1.TransactionDate AND T2.ID <= T1.ID)`.
Click the 'Run' button (the red exclamation mark) in the 'Design' tab to execute the query and view your dynamically numbered rows.
Handle Your Data and Reports Easily with WPS Office
While Microsoft Access requires complex SQL workarounds for simple tasks like row numbering, you can easily manage, analyze, and number large exported datasets using WPS Spreadsheet. WPS Office is a free, lightweight suite fully compatible with Microsoft Office files.

Frequently Asked Questions
Why can't I use the ROW_NUMBER() function in Microsoft Access?
Microsoft Access uses the Jet/ACE SQL engine, which does not support advanced window functions like ROW_NUMBER() found in SQL Server's T-SQL. You must rely on self-joins or DCount functions to replicate this behavior.
What happens if there are duplicate dates in my Access data?
If you use only a date field to generate row numbers and some dates duplicate, the count will return ties (the same row number for multiple records). You must include a unique field, like an AutoNumber primary key, in your SQL WHERE clause to correctly resolve these ties.
Is there a VBA alternative to generating row numbers in Access?
Yes, you can write a custom VBA function or use a Recordset loop to assign sequential numbers to a temporary table. However, using SQL self-joins is generally preferred for creating dynamic, up-to-date queries without writing custom code.
Can I export my Access data to a spreadsheet to add row numbers?
Absolutely. You can export your query or table results to a CSV or Excel file, open it in an application like WPS Spreadsheet, and use the drag-to-fill feature or the ROW() function to instantly generate sequential numbers without any coding.




