MySQL: Using user-defined variables

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

We can assign a value returned from a select statement to a user-defined variable.

This allows us to refer to it in later statements in the same session.

Those user-defined variables will not persist across sessions.

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

The max price was assigned to variable @max_price.

If you execute the 2 statements on Toad, the screenshot will look like below:




Series Navigation<< MySQL: Using mysqldump to backup database
MySQL: Handling special characters >>

Leave a comment

Leave a Reply