SELECT INTO and “Undeclared variable” error

前端 未结 10 2137
你的背包
你的背包 2020-11-30 06:58

When I try to execute following query:

SELECT id_subscriber
  INTO newsletter_to_send
  FROM subscribers 

I get an error:

相关标签:
10条回答
  • 2020-11-30 08:02

    I think you can follow my given way and hopefully you will be able to fix your problem.

    At first use this sql command to create a new table where you want to take backup

    CREATE TABLE destination_table_name LIKE source_table_name;
    

    After then you can use this command to copy those data

    INSERT INTO destination_table_name
    SELECT * FROM source_table_name;
    

    If you already have previous data in your Destination table , Firstly you can use this command

    TRUNCATE TABLE destination_table_name; 
    

    Thanks By Md. Maruf Hossain

    0 讨论(0)
  • 2020-11-30 08:04

    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. See Section 12.2.5.1, “INSERT ... SELECT Syntax”.

    Ref:- this

    0 讨论(0)
  • 2020-11-30 08:05
    CREATE TABLE table_name
    AS  
    SELECT ...(your select)
    0 讨论(0)
  • 2020-11-30 08:05

    MySQL does not support SELECT INTO [table]. It only supports SELECT INTO [variable] and can only do this one variable at a time.

    What you can do, however is use the CREATE TABLE syntax with a SELECT like so:

    CREATE TABLE bar ([column list]) SELECT * FROM foo;
    
    0 讨论(0)
提交回复
热议问题