Forum Moderators: open

Message Too Old, No Replies

Selecting random record by group

         

Ahhk

4:09 pm on Sep 17, 2008 (gmt 0)

10+ Year Member



Im hoping there is a SQL solution to this but I cant figure it out

I have a table of products (id, products, group_id) like:

1, product a, 1
2, product b, 1
3, product c, 1
4, product d, 1
5, product e, 2
6, product f, 2
7, product g, 2
8, product h, 3
9, product i, 3
10, product j, 3
11, product k, 3
12, product l, 3
13, product m, 4
14, product n, 4
15, product o, 4
16, product p, 4

and want to be able to select one random product from each group. I know how to do a random record, and I know how to do a group by. I just cant figure out the combo.

A result would be like:

product a, product g, product j, product m

TIA!

Ahhk

5:42 pm on Sep 20, 2008 (gmt 0)

10+ Year Member



Thanks, but I came up with a workaround!