Create a table + populate it using another table in One Query

I am using Access 2000 and I have 2 queries:

First:

CREATE TABLE first_table_name (....) 

Second:

 INSERT INTO first_table_name [(column1, column2, ... columnN)] SELECT column1, column2, ...columnN FROM second_table_name [WHERE condition]; 

Is it possible to do the same thing (create a table and immediately fill it with another table) with just one query?

Thanks!

+4
source share
6 answers

to try

 SELECT column1, column2, ...columnN into first_table_name FROM second_table_name [WHERE condition]; 

first_table_name will have the same table column as the name of the second table

+6
source
 SELECT column1, column2, ...columnN INTO new_table FROM second_table_name [WHERE condition]; 
+3
source

Method 1: INSERT IN SELECT

 INSERT INTO Table1 (col1, col2) SELECT col1, col2 FROM Table2 

Method 2: CHOOSE TO

 SELECT col1, col2 INTO Table1 FROM Table2 

Note. The table contains the same schema.

+1
source

Insertion into one table of records selected from another is possible, here is a document. in case you use mysql: mysql insert select

0
source
 CREATE TABLE new_table AS SELECT col1, col2, ... FROM second_table_name WHERE ... 
0
source

The only way to do this is:

SELECT blah INTO [ #local | ##global ] FROM ... WHERE

But this is not a permanent table and will disappear when ...

if #local table then when the user is disconnected if ## is a global table, then when all users using it disconnect

So not a good solution.

You can write a stored procedure to make create + insert, and then execute it in many places with just one subsequent statement, but this kind of hype with the answer.

0
source

All Articles