GNU Info

Info Node: (mysql.info)example-user-variables

(mysql.info)example-user-variables


Next: example-Foreign keys Prev: example-Maximum-column-group-row Up: Examples
Enter node , (file) or (file)node

Using user variables
--------------------

You can use MySQL user variables to remember results without having to
store them in temporary variables in the client.  Note: Variables.

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

     select @min_price:=min(price),@max_price:=max(price) from shop;
     select * from shop where price=@min_price or price=@max_price;
     
     +---------+--------+-------+
     | article | dealer | price |
     +---------+--------+-------+
     |    0003 | D      |  1.25 |
     |    0004 | D      | 19.95 |
     +---------+--------+-------+


automatically generated by info2www version 1.2.2.9