This should be a simple syntax thing:
I'm trying to set a variable in MySQL equal to the result of a query for instance:
SET @variable1 = SELECT salary FROM employee_info WHERE emp_id = 12345678;
Basically I want the salary from that employee to be stored as a variable that I can then manipulate and add.
What would the correct syntax for this be because I can't get it to work.
解决方案SELECT salary INTO @variable1 FROM employee_info WHERE emp_id = 12345678 LIMIT 1;
or
SET @variable1 = (SELECT salary FROM employee_info WHERE emp_id = 12345678 LIMIT 1);
SELECT @variable1;