Non-aggregating max()?

Non-aggregating max()?

Post by AndrHse » Fri, 10 Aug 2007 11:47:44


Hi,

since MAX() is an aggregate function, is there a "normal" MAX() that
works like this:

SELECT MAX(1,2);
-> 2

Regards,
Andr
 
 
 

Non-aggregating max()?

Post by Pavel Lepi » Fri, 10 Aug 2007 15:29:49


Andr Hnsel < XXXX@XXXXX.COM > wrote in
< XXXX@XXXXX.COM >:

mysql> SET @a=1;
Query OK, 0 rows affected (0.06 sec)

mysql> SET @b=2;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT IF(@a>@b,@a,@b);
+-----------------+
| IF(@a>@b,@a,@b) |
+-----------------+
| 2 |
+-----------------+
1 row in set (0.04 sec)

mysql> SELECT IF(@b>@a,@b,@a);
+-----------------+
| IF(@b>@a,@b,@a) |
+-----------------+
| 2 |
+-----------------+
1 row in set (0.00 sec)

Beware of NULLs.

--
...the pleasure of obedience is pretty thin compared with
the pleasure of hearing a rotten tomato hit someone in the
rear end. -- Garrison Keillor