Access两张共享Machine Name/RAM字段的表合并补全RAM数据需求
Alright, let's figure out how to merge those two Access tables and fill in as many missing RAM values as possible. Here's a practical, step-by-step solution that should get you exactly what you need:
Access doesn’t natively support FULL OUTER JOIN, so we’ll use a combination of LEFT JOIN and UNION to cover all machines from both tables, while prioritizing non-empty RAM values.
First, create a select query with this SQL:
-- Get all machines from Table1, use Table2's RAM if Table1's is empty SELECT t1.[Machine Name], Nz(t1.RAM, t2.RAM) AS RAM FROM Table1 t1 LEFT JOIN Table2 t2 ON t1.[Machine Name] = t2.[Machine Name] UNION -- Add machines that only exist in Table2 SELECT t2.[Machine Name], t2.RAM FROM Table2 t2 LEFT JOIN Table1 t1 ON t2.[Machine Name] = t1.[Machine Name] WHERE t1.[Machine Name] IS NULL
- The
Nzfunction here does the heavy lifting: if Table1’s RAM is empty, it pulls the RAM value from Table2 instead. - The
UNIONensures we don’t miss any machines that only appear in Table2.
If a machine has multiple entries in either table, we’ll group them to keep only one record per machine, retaining the first non-empty RAM value. Wrap the previous query in a grouping query:
SELECT [Machine Name], First(Nz(RAM, NULL)) AS RAM FROM ( -- Paste the entire UNION query from Step 1 here SELECT t1.[Machine Name], Nz(t1.RAM, t2.RAM) AS RAM FROM Table1 t1 LEFT JOIN Table2 t2 ON t1.[Machine Name] = t2.[Machine Name] UNION SELECT t2.[Machine Name], t2.RAM FROM Table2 t2 LEFT JOIN Table1 t1 ON t2.[Machine Name] = t1.[Machine Name] WHERE t1.[Machine Name] IS NULL ) AS CombinedData GROUP BY [Machine Name]
- If you suspect conflicting RAM values for the same machine (e.g., different entries show 8GB and 16GB), replace
FirstwithMaxorMinto pick a consistent value—just make sure it makes sense for your data.
Once you’ve verified the query returns the right results (run it first to check!), convert it to a make-table query:
- In Access’s query design view, go to the
Query Typemenu and selectMake-Table Query. - Name your new table (e.g.,
CombinedMachineSpecs) and click OK. - Run the query—Access will create the new table with all merged, cleaned data.
- If a machine has empty RAM in both tables, we can’t magic up a value—those will stay empty, but this approach minimizes that as much as possible.
- Always back up your original tables before running make-table queries, just in case you need to revert!
内容的提问来源于stack exchange,提问作者Storm2508

