Home >Database >Mysql Tutorial >How to Correctly Insert Extracted Data into a New Table in MS Access?
Moving Data Between MS Access Tables: A Guide
In MS Access databases, you'll often need to move data from one table to another, often after some transformation. The INSERT INTO
statement is key, but incorrect syntax can lead to errors.
Troubleshooting Syntax Errors
A common mistake when using INSERT INTO
with a subquery is including extra elements. The VALUES
keyword and parentheses around the subquery are unnecessary in this context.
Correct Syntax for Data Insertion
Here's the correct approach:
<code class="language-sql">INSERT INTO Table2 (LongIntColumn2, CurrencyColumn2) SELECT LongIntColumn1, Avg(CurrencyColumn) AS CurrencyColumn1 FROM Table1 GROUP BY LongIntColumn1;</code>
This streamlined query efficiently extracts data from Table1
, groups it by LongIntColumn1
, computes the average of CurrencyColumn
, and inserts the results into Table2
's LongIntColumn2
and CurrencyColumn2
fields. This eliminates syntax errors and ensures data integrity.
The above is the detailed content of How to Correctly Insert Extracted Data into a New Table in MS Access?. For more information, please follow other related articles on the PHP Chinese website!