I am using a select into variable query in two ways as follows:
SELECT @var1:=columnname1, @var2:=columnname2 FROM tbname WHERE menuname='somevalue': this is working
SELECT columnname1,columnname2 INTO @var1,@var2 FROM tbname WHERE menuname='somevalue' : this is not working in all cases Returns null sometimes
Please can anyone guide me why the (2) query works only sometimes and which is the more appropriate way. While when I run query (1) for the same where condition as in (2), it gives me results.
解决方案
I resolved my problem by using the following for query (2)
SELECT columnname1,columnname2 INTO @var1,@var2 FROM tbname WHERE menuname='somevalue' limit 1; SELECT @var1;
which now returns me the value of variable2. I was missing the select @var1 statement
Thank you for all your help