How to Add a Flag Column by Matching Values Between Two Access Tables
Question details
Create a query or column that flags records with a 1 or 0 depending on whether an item number from a main table exists in a second table, without dropping any rows from the main table.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Generating a comprehensive report that requires all original data plus a new indicator for matches found in a secondary qualifying table.
- Observed behavior
- Needs to retain every row from the first table while successfully identifying matched items using a binary flag.
Ensure both tables have an item number field with identical data types to prevent query errors, and verify that the second table contains no duplicate item numbers to avoid unintentional row duplication.
Use a LEFT JOIN with an IIf Calculation
This method ensures all records from your main table are preserved while returning a 1 or 0 flag based on matched records.
A LEFT JOIN includes all rows from the first (left) table and only matching rows from the second (right) table. By evaluating if the matched field is null using the IIf function, you can dynamically generate a 0 or 1 flag without modifying the underlying table data.
Open your database, navigate to the Create tab on the top ribbon, and click on Query Design.
Add both your main table and the secondary table containing the qualifying item numbers to the query designer workspace.
Click and drag the item number field from your main table to the matching field in the second table to create a relationship line.
Double-click the relationship line, and select the join property option that includes 'all records from the main table and only those records from the second table where the joined fields are equal'.
Add all the required fields from the main table to the query design grid below.
In a new blank column on the grid, enter the calculated field: MatchFlag: IIf([MatchedTable].[ItemNumber] Is Null, 0, 1). Replace 'MatchedTable' with the actual name of your second table.
Click the Run button (red exclamation mark) to view the results. You will see all original rows with a 1 for matched items and a 0 for unmatched items.

Analyze Your Exported Database Reports with WPS Office
While Microsoft Access handles complex database queries, you might need a lightweight, cost-effective solution for everyday spreadsheet analysis and document tasks. WPS Office provides a powerful, free alternative to Microsoft Office.
- 1. Export Access Data: Export your completed Access query results to an Excel (.xlsx) or CSV format.
- 2. Open with WPS Spreadsheet: Launch WPS Office and open your exported data file to begin formatting and analysis.
- 3. Analyze and Share: Use built-in data visualization tools, charts, and PivotTables to seamlessly report your findings.

Frequently Asked Questions
Why does my query return duplicate rows from the first table?
This happens if the second table contains multiple records with the same item number. To fix this, you must ensure the matching field in the second table contains only unique values, typically by grouping it or setting it as a Primary Key before joining.
Can I use an INNER JOIN instead of a LEFT JOIN for this?
No. An INNER JOIN only returns rows where there is a match in both tables. Since your goal is to retain every row from the first table regardless of whether a match exists, a LEFT JOIN is absolutely required.
What happens if the data types of the item numbers don't match?
Microsoft Access will throw a 'Type Mismatch' error in the join expression. You must open both tables in Design View and ensure both fields are configured with the exact same data type (e.g., both as Short Text or both as Number).




