8

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

4 Answers 4

17

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Have two set statements. Set one with the select statement and then copy the value in the first to the second.

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

Comments

1
select vFN :=fname, vLN:=lname from sometable where id = 1

Comments

1

Forgive me if this doesn't work in MySQL, because I'm used to TSQL syntax. But you should be able to do something like:

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

Or if you need to do select into with mysql:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.