Hi,

I was hoping that someone could help me with something that's been stumping me.

I want to do, as the subject suggests, a top N values per group query and I was wondering if there was a way to do it "The Ruby Way" as opposed to writing a complicated find_by_sql or some such.

Here it is:

Table Stuff

id
title
category_id

Table Categories

id
name

Stuff has many categories.

Let's say in the Categories table, I have the values "books, dvds, music, games."

What I want to do is select the first N from each category. So one (or two or three..., depending what N is) from books, music, dvd, and games.

I haven't found very many ways to do this in SQL without writing complicated queries (see this example: http://support.microsoft.com/ kb/210039/en-us) so I was hoping that Ruby\Rails had some magic coolness that I didn't know about.

Thanks to anyone in advance that can help me.

If you're going to FOSCON, I'll see you there!

Carlos Rodriguez
[EMAIL PROTECTED]

_______________________________________________
PDXRuby mailing list
[email protected]
IRC: #pdx.rb on irc.freenode.net
http://lists.pdxruby.org/mailman/listinfo/pdxruby

Reply via email to