Unix Technical Forum

Group by Top x ?

This is a discussion on Group by Top x ? within the MySQL forums, part of the Database Server Software category; --> Consider a query like, e.g. SELECT GROUP_CONCAT(id) FROM `products` GROUP BY `brand`; Then the result will be product id ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:27 AM
howa
 
Posts: n/a
Default Group by Top x ?

Consider a query like, e.g.

SELECT GROUP_CONCAT(id) FROM `products` GROUP BY `brand`;

Then the result will be product id string group by brand name


However, I want to limit the GROUP_CONCAT() only return the top 3
products of each brand, say, by price

How to do this?

Thanks.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 11:27 AM
Captain Paralytic
 
Posts: n/a
Default Re: Group by Top x ?

On 3 Sep, 16:16, howa <howac...@gmail.com> wrote:
> Consider a query like, e.g.
>
> SELECT GROUP_CONCAT(id) FROM `products` GROUP BY `brand`;
>
> Then the result will be product id string group by brand name
>
> However, I want to limit the GROUP_CONCAT() only return the top 3
> products of each brand, say, by price
>
> How to do this?
>
> Thanks.


There are just SO MANY answers around to this already!
I just Googled "mysql top n group" and got a massive list.
Here's a link to the first one:

http://thenoyes.com/littlenoise/?p=36

Amazed you couldn't do this too!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:07 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com