MySQL: Setting a select result to a variable

This entry is part 22 of 26 in the series Learn MySQL

SET also can be used to assign a SELECT result to a variable, provided that you write the SELECT as a subquery , that is, within parentheses(), and it returns a single value.

set @max_price := (select max(price) from artist);
select @max_price;


Series Navigation<< MySQL: Setting a variable to a value
MySQL: Numbering query output lines >>