MySQL: Assign expression to a variable

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

The variables in the select statement can also be assigned values from arbitrary expressions.

In the following statements, it find the max value from the price column.

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

e1

e2

e3

 

 

Series Navigation<< MySQL: Returning multiple rows of values
MySQL: Saving the last inserted id using LAST_INSERT_ID() >>