Ronin Web Ronin Web - 16 days ago 7
MySQL Question

MySQL GROUP BY (if)

edited: sorry badly asked..

i want to GROUP BY a variable only if another variable is equal.

i have this:

username name forename

jpumpkin_01 Pumpkin Jack
jpumpkin_02 Pumpkin Jack
pnice Nice Paul
mpumpkin Pumpkin Michael


i display the content with:

SELECT * FROM ... WHERE ...


this lists all entries:

Pumpkin Jack
Pumpkin Jack
Nice Paul
Pumpkin Michael


"Pumpkin Jack" is listed double. I use GROUP BY 'name'

... GROUP BY name


Now, "Pumpkin Jack" is listed one time, but "Pumpkin Michael" is in the group too, and disapeared.

How can i list also Michael?

Thank you for answers and hints..

rgs

R

Answer

The GROUP BY is not conditional. So what you can do is something like this: "SELECT * FROM ... WHERE ... GROUP BY name, forename".