Hi!


>>>>> "Tobias" == Tobias K Tobiasen <[EMAIL PROTECTED]> writes:

<cut>

mysql> select * from shop GROUP BY article;
Tobias> +---------+--------+-------+
Tobias> | article | dealer | price |
Tobias> +---------+--------+-------+
Tobias> |    0001 | A      |  3.45 |
Tobias> |    0002 | A      | 10.99 |
Tobias> |    0003 | B      |  1.45 |
Tobias> |    0004 | D      | 19.95 |
Tobias> +---------+--------+-------+
Tobias> 4 rows in set (0.00 sec)

Tobias> QUESTION: I had expected 7 rows - where did the rest go?

GROUP BY groups all rows with the same article together ; As you had
only 4 different groups you only got for rows.

mysql> select * from shop GROUP BY article having price=max(price);
Tobias> +---------+--------+-------+
Tobias> | article | dealer | price |
Tobias> +---------+--------+-------+
Tobias> |    0002 | A      | 10.99 |
Tobias> |    0004 | D      | 19.95 |
Tobias> +---------+--------+-------+
Tobias> 2 rows in set (0.00 sec)

Tobias> QUESTION: I had expected 4 rows (one for each article) - where did the 
Tobias> rest go?

The query 'price=max(price)' is a non-sense condition that is not
really allowed in SQL;  In MySQL the 'price' here is the price for
'some randomly chosen row' of the rows in the group; (You can read
more about this in the group-by extension in the MySQL manual)

(In other words, don't use this feature if you are not 100 % sure how
it works)

Regards,
Monty

-- 
For technical support contracts, goto https://order.mysql.com/
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /    Mr. Michael Widenius <[EMAIL PROTECTED]>
 / /|_/ / // /\ \/ /_/ / /__   MySQL AB, CTO
/_/  /_/\_, /___/\___\_\___/   Helsinki, Finland
       <___/   www.mysql.com


---------------------------------------------------------------------
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 <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to