Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT INTO in MySQL

Tags:

sql

mysql

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?

like image 914
Mandeep Singh Avatar asked May 29 '13 08:05

Mandeep Singh


People also ask

Does SELECT into work in MySQL?

MySQL Server doesn't support the SELECT ... INTO TABLE Sybase SQL extension. Instead, MySQL Server supports the INSERT INTO ... SELECT standard SQL syntax, which is basically the same thing.

What is SELECT into in SQL?

The SELECT INTO command copies data from one table and inserts it into a new table. The following SQL statement creates a backup copy of Customers: SELECT * INTO CustomersBackup2017.

What is SELECT into used for?

The SELECT INTO statement is a query that allows you to create a new table and populate it with the result set of a SELECT statement . To add data to an existing table, see the INSERT INTO statement instead. SELECT INTO can be used when you are combining data from several tables or views into a new table.

What is SELECT into query?

Introduction to SQL Server SELECT INTO statement The SELECT INTO statement creates a new table and inserts rows from the query into it. If you want to copy the partial data from the source table, you use the WHERE clause to specify which rows to copy.


1 Answers

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; 
like image 175
Dave K Avatar answered Sep 19 '22 14:09

Dave K