List:General Discussion« Previous MessageNext Message »
From:Fournier Jocelyn [Presence-PC] Date:April 4 2002 7:35pm
Subject:Re: Group by?
View as plain text  
----- Original Message ----- 
From: "Tobias K. Tobiasen" <tobiasen@stripped>
To: <mysql@stripped>
Sent: Thursday, April 04, 2002 6:46 PM
Subject: Group by?


> Hello
> 
> I think the gruop by is behaving strange. Could someone please explain 
> this or maybe point me to a definition of the group by. (Inspired by 
> http://www.mysql.org/doc/E/x/Examples.html).
> 
> 
> CREATE TABLE shop (
>   article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
>   dealer  CHAR(20)                 DEFAULT ''     NOT NULL,
>   price   DOUBLE(16,2)             DEFAULT '0.00' NOT NULL,
>   PRIMARY KEY(article, dealer));
> 
> INSERT INTO shop VALUES
> (1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69),
> (3,'D',1.25),(4,'D',19.95);
> 
> mysql> SELECT * FROM shop;
> 
> +---------+--------+-------+
> | article | dealer | price |
> +---------+--------+-------+
> |    0001 | A      |  3.45 |
> |    0001 | B      |  3.99 |
> |    0002 | A      | 10.99 |
> |    0003 | B      |  1.45 |
> |    0003 | C      |  1.69 |
> |    0003 | D      |  1.25 |
> |    0004 | D      | 19.95 |
> +---------+--------+-------+
> 7 rows in set (0.00 sec)
> 
> mysql> select * from shop GROUP BY article;
> +---------+--------+-------+
> | article | dealer | price |
> +---------+--------+-------+
> |    0001 | A      |  3.45 |
> |    0002 | A      | 10.99 |
> |    0003 | B      |  1.45 |
> |    0004 | D      | 19.95 |
> +---------+--------+-------+
> 4 rows in set (0.00 sec)
> 
> QUESTION: I had expected 7 rows - where did the rest go?

Try SELECT * FROM shop GROUP BY article,dealer;

(same thing for the rest of queries)

Regards,

Jocelyn Fournier
Presence-PC

Thread
Group by?Tobias K. Tobiasen4 Apr
  • Re: Group by?Gerald Clark4 Apr
  • Re: Group by?Fournier Jocelyn [Presence-PC]4 Apr
  • Re: Group by?Harald Fuchs5 Apr
  • Group by?Michael Widenius5 Apr