views:

379

answers:

4

Hello !

When I try to execute following querry:

SELECT id_subscriber
  INTO newsletter_to_send
  FROM subscribers 

I get an error:

#1327 - Undeclared variable: newsletter_to_send

What is wrong with that query ?

+3  A: 
INSERT ... SELECT

http://dev.mysql.com/doc/refman/5.1/en/insert-select.html

INSERT INTO newsletter_to_send
SELECT id_subscriber FROM subscribers 

PS: are you sure you don't need in WHERE clause?

zerkms
Works fine, thanks !
hsz
+1  A: 

MySQL does not support the SELECT ... INTO ... syntax.

You have to use the INSERT INTO ... SELECT .. syntax to accomplish there.

Read more here.. http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

Raj More
A: 

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

Salil
A: 

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;
amphetamachine