PHP/mySQL question about groups
| From: | Rob Gould | Date: | Thu, 07 Feb 2008 01:46:52 +0000 |
| Subject: | PHP/mySQL question about groups | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-268823@lists.php.net to get a copy of this message | ||
Let's say I have a PHP-based wine application, and it's taking a set of mySQL data that
looks like this:
wineid name size
123 Silver Oak 750ML
123 Silver Oak 1.5L
123 Silver Oak 1.5L
456 Liberty School 750ML
456 Liberty School 750ML
456 Liberty School 750ML
456 Liberty School 1.5L
If I do a:
Select * from wine where name = 'Silver Oak' GROUP BY 'wineid'
I'd get:
Silver Oak
However, what I'd REALLY like to return is:
Silver Oak 750ML
Silver Oak 1.5L
I'd like the groupby to group by wineid, BUT ALSO separate the groups by 'size'. So
there'd be a '750ML' group, and a '1.5L' group
Can anyone tell me how I'd do that? I'm hoping I don't have to write a PHP script
that loops through the results and separates things manually.