How to store Query Result in variable using mysql How to store Query Result in variable using mysql database database

How to store Query Result in variable using mysql


Surround that select with parentheses.

SET @v1 := (SELECT COUNT(*) FROM user_rating);SELECT @v1;


Additionally, if you want to set multiple variables at once by one query, you can use the other syntax for setting variables which goes like this: SELECT @varname:=value.

A practical example:

SELECT @total_count:=COUNT(*), @total_price:=SUM(quantity*price) FROM items ...


use this

 SELECT weight INTO @x FROM p_status where tcount='value' LIMIT 1;

tested and workes fine...