MYSQL, set two variables in stored proc with single select statement

davej picture davej · Mar 2, 2012 · Viewed 13.9k times · Source

So I'd like it to be something like, or have the effect of:

declare vFN varchar(20); 
declare vLN varchar(20);
set vFN, vLN = (select fname, lname from sometable where id = 1);

Obviously, I could do 2 selects, but that seems very inefficient.

tia

Answer

Jerome WAGNER picture Jerome WAGNER · Mar 2, 2012

you should try

declare vFN varchar(20); 
declare vLN varchar(20);
select fname, lname INTO vFN, vLN from sometable where id = 1;

check http://dev.mysql.com/doc/refman/5.0/en/select-into.html for documentation.