Introduction
Variables let you store temporary values in your database session. SET statements assign values to these variables so you can use them later in your queries.
When you want to store a value to use multiple times in a query.
When you need to calculate a value once and reuse it in several places.
When you want to make your query easier to read by naming important values.
When you want to change a value quickly without rewriting the whole query.