Documentation Home
MySQL 5.6 リファレンスマニュアル
Download this Manual
PDF (US Ltr) - 26.8Mb
PDF (A4) - 26.9Mb
HTML Download (TGZ) - 7.1Mb
HTML Download (Zip) - 7.2Mb SELECT INTO TABLE の違い

MySQL Server では、Sybase SQL 拡張機能 SELECT ... INTO TABLE はまだサポートされていません。MySQL Server では代わりに、基本的に同じ処理を行う INSERT INTO ... SELECT 標準 SQL 構文がサポートされています。セクション13.2.5.1「INSERT ... SELECT 構文」を参照してください。例:

INSERT INTO tbl_temp2 (fld_id)
    SELECT tbl_temp1.fld_order_id
    FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;

あるいは、SELECT ... INTO OUTFILE または CREATE TABLE ... SELECT を使用することもできます。

ユーザー定義変数で SELECT ... INTO を使用できます。カーソルとローカル変数を用いてストアドルーチン内でも同じ構文を使用できます。セクション13.2.9.1「SELECT ... INTO 構文」を参照してください。

User Comments
  Posted by Sean Nolan on March 24, 2005
This topic states that INSERT ... SELECT is basically the same as the Sybase SELECT ... INTO TABLE statement. That is wrong, the two are very different. SELECT ... INTO TABLE creates a NEW table with the rows from the SELECT, this is completely different from INSERT ... SELECT, which just appends rows to an existing table.

It is correct to say that the MySql CREATE TABLE ... SELECT statement is basically the same as the Sybase SELECT ... INTO TABLE statement.

Microsoft SQL Server also supports SELECT ... INTO TABLE.

  Posted by Ann B on July 29, 2005
With INSERT..SELECT you must first have created the table. If you wish to create the table with the select, use CREATE..SELECT.
  Posted by Geo Cabs on April 26, 2006
If table structure is the same then you can use:
INSERT INTO `table2` SELECT * FROM `table1`;
  Posted by Matthew Green on May 29, 2006
Syabse select/into is also a minimally logged operation, making it much faster than So, as already stated it is not the same thing by a long way!
  Posted by Heinz Mueller on November 4, 2009
There is an alternative for the "select into problem":

create table mynewtable (select * from myoldtable)
  Posted by M. Hamed A. on December 3, 2011
SELECT INTO tries to make a table based on the output of the SELECT statement but it lacks many definitions those you could have in CREATE TABLE statement. for instance the indexes (PRIMARY, UNIQUE, etc.) are not created in output table of SELECT INTO command or you can't set a DEFAULT for some created fields.

According to this situation, CREATE ... SELECT command of MySQL is somehow better and more complete than the SELECT INTO syntax.
Sign Up Login You must be logged in to post a comment.