SELECT INTO in MySQL

MysqlSql

Mysql Problem Overview


I am a MSSQL user and now I am converting my database to MySQL. I am writing the following query in MySQL:

SELECT * INTO new_tbl FROM tbl;

And I get the following error

Error : Undeclared variable new_tbl

How such a query should be properly written in MySQL?

Mysql Solutions


Solution 1 - Mysql

Use the CREATE TABLE SELECT syntax.

http://dev.mysql.com/doc/refman/5.0/en/create-table-select.html

CREATE TABLE new_tbl SELECT * FROM orig_tbl;

Solution 2 - Mysql

In MySQL, It should be like this

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMandeep SinghView Question on Stackoverflow
Solution 1 - MysqlDave KView Answer on Stackoverflow
Solution 2 - MysqlMuhammad HaniView Answer on Stackoverflow