SELECT INTO and "Undeclared variable" error

hsz picture hsz · Jun 1, 2010 · Viewed 81k times · Source

When I try to execute following query:

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 ?

Answer

zerkms picture zerkms · Jun 1, 2010
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?