SELECTcol_name[,...] INTOvar_name[,...]table_expr
This SELECT syntax stores selected columns
directly into variables. Therefore, only a single row may be
retrieved.
SELECT id,data INTO x,y FROM test.t1 LIMIT 1;
User variable names are not case sensitive. See Section 9.4, “User-Defined Variables”.
Important: SQL variable names
should not be the same as column names. If an SQL statement,
such as a SELECT ... INTO statement,
contains a reference to a column and a declared local variable
with the same name, MySQL currently interprets the reference
as the name of a variable. For example, in the following
statement, xname is interpreted as a
reference to the xname
variable rather than the
xname column:
CREATE PROCEDURE sp1 (x VARCHAR(5))
BEGIN
DECLARE xname VARCHAR(5) DEFAULT 'bob';
DECLARE newname VARCHAR(5);
DECLARE xid INT;
SELECT xname,id INTO newname,xid
FROM table1 WHERE xname = xname;
SELECT newname;
END;
When this procedure is called, the newname
variable returns the value 'bob' regardless
of the value of the table1.xname column.
See also Section D.1, “Restrictions on Stored Routines and Triggers”.

User Comments
NOTE: this is very different for MS SQL Server (or Sybase) where SELECT ... INTO will create a new table.
Regarding what Frank Flynn said:
this SELECT ... INTO ... statement has nothing to do with the SELECT ... INTO statement he's talking about. This one is for use within stored procedures and functions (and assigns values retrieved through the query to variables - that's why it says the select must return only one row). MySQL has the SELECT ... INTO Frank Flynn talks about, although in MySQL data is dumped to an outfile, not a table.
When SELECT returns no rows, then the variables stay unchanged !
Dont you suppose that the variables will assigned to NULL.
Add your own comment.