Search the MySQL manual:

3.5.5 Using user variables

You can use MySQL user variables to remember results without having to store them in temporary variables in the client. See section 6.1.4 User Variables.

For example, to find the articles with the highest and lowest price you can do:

mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
|    0003 | D      |  1.25 |
|    0004 | D      | 19.95 |
+---------+--------+-------+

User Comments

Add your own comment.