[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Select and =MAX()


In article <006701c0ff93$e33e9a20$0100a8c0@jorge>,
"Jorge del Conde" <jorge@xxxxxxxxx> writes:

> Hi,
> What version of MySQL are you using ?
> How is price defined ?  .. In the below example, I defined price as
> float(9,2).

mysql> SELECT *
-> FROM a;
> +-------+
> | price |
> +-------+
> | 19.95 |
> | 10.99 |
> |  3.99 |
> |  3.45 |
> |  1.69 |
> |  1.45 |
> |  1.25 |
> +-------+
> 7 rows in set (0.01 sec)

mysql> SELECT price
-> FROM a
-> HAVING price=MAX(price);
> +-------+
> | price |
> +-------+
> | 19.95 |
> +-------+
> 1 row in set (0.01 sec)

That's interesting.  When I do

  CREATE TABLE t1 (
    price FLOAT(9,2) NOT NULL
  );
  INSERT INTO t1 (price) VALUES (19.95);
  INSERT INTO t1 (price) VALUES (10.99);
  INSERT INTO t1 (price) VALUES ( 3.99);
  INSERT INTO t1 (price) VALUES ( 3.45);
  INSERT INTO t1 (price) VALUES ( 1.69);
  INSERT INTO t1 (price) VALUES ( 1.45);
  INSERT INTO t1 (price) VALUES ( 1.25);

the query

  SELECT price FROM t1 HAVING price = MAX(price);

returns correctly 19.95.

But when I switch the first two INSERTs (first 10.99, then 19.95),
the same query returns an empty result set.  Any explanation for that?

(mysql-max 3.23.39, linux 2.2.18)

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <mysql-thread77907@xxxxxxxxxxxxxxx>
To unsubscribe, e-mail <mysql-unsubscribe-treed=ultraviolet.org@xxxxxxxxxxxxxxx>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



This mailing list archive is a service of Copilot Consulting.