【问题标题】:MySQL does not support select INTO?MySQL 不支持 select INTO?
【发布时间】:2015-08-26 06:12:52
【问题描述】:

我的以下 SQL 查询有来自 MySQL 工作台的错误,错误是无法识别表“new_table”。是不是说 MySQL 不支持 select into 语句?

SELECT student_id 
into new_table
FROM students;

提前致谢, 林

【问题讨论】:

  • @IgnazioC:- 不,它没有。请通过链接。 OP 已询问是否将数据插入表中。

标签: mysql sql


【解决方案1】:

问题是MySQL does not support the SELECT ... INTO ... syntax

你必须像这样使用它:

Insert into new_table
Select * FROM students;

【讨论】:

    【解决方案2】:

    使用

    insert into new_table
      Select * FROM students;
    

    【讨论】:

    • 谢谢@Bernd,MySQL 不支持 select into 吗?
    【解决方案3】:

    使用

    CREATE TABLE new_table as SELECT student_id FROM students;
    

    如果表已经存在:

    INSERT INTO new_table SELECT * FROM students;
    

    This thread 有一些语法差异的细节。

    【讨论】:

    • MySQL 不支持 select into?
    • 语法略有不同。
    【解决方案4】:

    你可以试试这个方法:

    INSERT INTO new_table (student_id)
    SELECT student_id FROM students
    

    我的带数据的sql中的两表表结构:

    /*Table structure for table `new_table` */
    
    CREATE TABLE `new_table` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `student_id` int(11) DEFAULT NULL,
      `name` varchar(100) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
    /*Data for the table `new_table` */
    insert  into `new_table`(`id`,`student_id`,`name`) values (1,401,NULL),(2,402,NULL);
    
    /*Table structure for table `students` */
    CREATE TABLE `students` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `student_id` int(11) DEFAULT NULL,
      `name` varchar(100) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
    /*Data for the table `students` */
    insert  into `students`(`id`,`student_id`,`name`) values (1,401,'matin'),(2,402,'rahman');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-21
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 2017-09-30
      • 2018-05-13
      • 2012-04-07
      • 2012-03-11
      相关资源
      最近更新 更多