Summarizing a column to a DISTINCT value

Summarizing a column to a DISTINCT value

am 09.09.2006 20:52:26 von worldcyclist

Hey folks,
I am just getting into MySQL and have run into a problem with
subqueries.
I am running MySQL 4.0.21 and I am trying to CONCAT and I have no idea
where I'm tripping up...

The data looks like this....

+----+------------+---------+
| id | product | color |
+----+------------+---------+
| 1 | mixer | blue |
| 2 | mixer | green |
| 3 | mixer | yellow |
+----+------------+

I need to generate this....
+----+------------+---------+
| id | product | color |
+----+------------+---------+
| 1 | mixer | blue/green/yellow |
+----+------------+

In short, for each distinct product, generate a color field where the
all the choices are concatenated by a slash.

My apologies if this is remarkably simple. The real world query is
actually more brutal than this one which I have reduced for simplicity.

Sherabg

Re: Summarizing a column to a DISTINCT value

am 10.09.2006 13:43:49 von zac.carey

worldcyclist@gmail.com wrote:
> Hey folks,
> I am just getting into MySQL and have run into a problem with
> subqueries.
> I am running MySQL 4.0.21 and I am trying to CONCAT and I have no idea
> where I'm tripping up...
>
> The data looks like this....
>
> +----+------------+---------+
> | id | product | color |
> +----+------------+---------+
> | 1 | mixer | blue |
> | 2 | mixer | green |
> | 3 | mixer | yellow |
> +----+------------+
>
> I need to generate this....
> +----+------------+---------+
> | id | product | color |
> +----+------------+---------+
> | 1 | mixer | blue/green/yellow |
> +----+------------+
>
> In short, for each distinct product, generate a color field where the
> all the choices are concatenated by a slash.
>
> My apologies if this is remarkably simple. The real world query is
> actually more brutal than this one which I have reduced for simplicity.
>
> Sherabg

So what does your query for this hypothetical problem look like?