MySQL SELECT, store in a variable

Posted by rlb.usa on Stack Overflow See other posts from Stack Overflow or by rlb.usa
Published on 2010-05-04T19:06:39Z Indexed on 2010/05/04 19:58 UTC
Read the original article Hit count: 319

For a stored procedure, I want to do a SELECT, and store a column's value into a variable.

How do I do this?

I want to do something like this:

    DECLARE countTemp INT;
    SET countTemp=(SELECT COUNT(Name) FROM mytable WHERE Name= var_name LIMIT 0,1);

OR, like this :

    DECLARE countTemp INT;
    SELECT countTemp=ColumnXYZ FROM mytable WHERE Name= var_name LIMIT 0,1;

But, I tried these and MySQL says my syntax is incorrect; how do I do something like this?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about select