SELECT INTO Multiple Variable in MySQL declaration

10,135

Just list them out with commas after the INTO:

SELECT a, b, c
INTO v_a, v_b, v_C
FROM ...
Share:
10,135
Pragnesh Karia
Author by

Pragnesh Karia

Having an overall IT experience of 10+ years in developing, testing and deploying various projects using open source technology / solutions available. Majorly worked on Magento powerful open source shopping cart which is built on zend framework.Also on jQuery,core php and integartion of payment gateways in different open source shopping carts. My area of expertise are: PHP, Magento, jQuery, WordPress, Joomla, Drupal,MySQL ,Javascript, AJAX, CSS HTML, HTML5, XML, SEO, MOODLE LMS, OPEN CART, SpringCM Workflow Implementation, Salesforce Custom Object Relationship, Yardi, CRM, ERP **Open Source Enthusiast, Web Engineer **

Updated on June 14, 2022

Comments

  • Pragnesh Karia
    Pragnesh Karia about 2 years

    Is that possible to set two parameters value in single query in Stored Procedure Mysql? I want , two different parameters as output , i don't want to con-cat it.

    Declare v_first_name varchar(100);
    Declare v_last_name Varchar(100);
    
    SET p_email_id = 'some_email_id';
    
    /* 
    instead of this i want to laod result in single query   
    Set v_first_name=(Select first_name From user_master Where email_id=p_email_id);
    Set v_last_name=(Select last_name From user_master Where email_id=p_email_id);
    
    */
    
    if flag1=1 then 
    Select 1 As 'Result',v_first_name As 'first_name',v_last_name As 'last_name';  
    else    
    Select 0 As 'Result',v_first_name As 'first_name',v_last_name  As 'last_name';
    End if;
    

    Any help ?

    select first_name INTO @v_first_name , last_name INTO @v_last_name From user_master Where email_id=p_email_id; ==== **Not Working**
    
  • Kailas
    Kailas over 9 years
    Hi @siride. How can get these value in next select query like (SELECt id, name, v_a as value1, v_b as value2 FROM table WHERE id =1)
  • siride
    siride over 9 years
    @Kailas: I don't understand the question. Your example SELECT is exactly how you'd get them out.
  • Fakipo
    Fakipo almost 4 years
    why is this not working inside a concat query in stored procedure?
  • siride
    siride almost 4 years
    @Fakipo Did you declare the variables first? I'd ask in a new question first.
  • Fakipo
    Fakipo almost 4 years
    No, it works. we just have to use user defined variables..