+----+--------+
| id | color  |
+----+--------+
|  1 | red    |
|  2 | blue   |
|  3 | red    |
|  4 | yellow |
|  5 | yellow |
|  6 | blue   |
| .. | ...    |

I'm trying to select 5 random records, but no more than 1 of any given color. According to the notes in the documentation and to my own testing (I'm on v4.x), this doesn't work:

select id,distinct(color) from tablename order by rand();

I found that using 'group by color' works to limit it to one of each color, but the problem is I always get the same record of each color. I need to mix it up and give me different random records every time:

select id,color from tablename group by color order by rand();

This should be so easy!! What's the obvious solution that I'm missing?

- Brian

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to