Coder Perfect

SELECT INTO is a MySQL command.


I was previously using MSSQL and am now migrating to MySQL. In MySQL, I’m writing the following query:

SELECT * INTO new_tbl FROM tbl;

In addition, I receive the following error:

Error : Undeclared variable new_tbl

How should such a query be written properly in MySQL?

Asked by Mandeep Singh

Solution #1

Use the CREATE TABLE SELECT syntax to create a table.

CREATE TABLE new_tbl SELECT * FROM orig_tbl;

Answered by Dave K

Solution #2

It should look like this in MySQL.

INSERT INTO this_table_archive (col1, col2, ..., coln)
SELECT col1, col2, ..., coln
FROM this_table
WHERE entry_date < '2011-01-01 00:00:00';

MySQL Documentation

Answered by Muhammad Hani

Post is based on