Sir, look up Rand and ORDER BY in the documentation. I believe
there's an example of using Rand and ORDER BY to do this.
Bob Hall
>Thanks for the answer. but actually I'm not saying that mysql is doing
>wrong, I just want to know HOW can I group by codigo and then get 10 random
>rows of the grouped ones.
>
>Hope I explain me.
>
>Thanks again.
>
>
> > Angel Behar wrote:
> > >
> > > Hi !!!
> > >
> > > I'm running 3.23.28-gamma under windows NT, but I have the following
> > > problem.
> > > I need to query some data and gruop by some field (codigo in this case)
>so I
> > > run the following query :
> > >
> > > SELECT codigo from ropa where cve_depto='3' AND cve_clase='06' AND
>activo =
> > > 'A' AND p_credito <> 0 GROUP BY codigo;
> > >
> > > +--------+
> > > | codigo |
> > > +--------+
> > > | 319066 |
> > > +--------+
> > > 1 row in set (0.43 sec)
> > >
> > > the results are as I expected BUT I need to GROUP BY RAND() too and
>LIMIT to
> > > 10 rows :
> > >
> > > SELECT codigo from ropa where cve_depto='3' AND cve_clase='06' AND
>activo =
> > > 'A' AND p_credito <> 0 GROUP BY codigo, RAND() LIMIT 10;
> > >
> > > +--------+
> > > | codigo |
> > > +--------+
> > > | 319066 |
> > > | 319066 |
> > > | 319066 |
> > > +--------+
> > > 3 rows in set (0.30 sec)
> > >
> > > Actually I try switching codigo, RAND() or viceversa but doesn't work
> > > either.
> > >
> > > As you can see once I use the RAND() option doesn't group codigo, I need
> > > this because most of the articles are more than 10 but I really need to
> > > solve this problem.
> > >
> > > Hope anybody can help me.
> > >
> > > Thanks in advance.
> > >
> > > Angel
> > >
> > >
> > Each of those 3 lines have a different rand(), so it is doing it right.
> >
> > ---------------------------------------------------------------------
> > Before posting, please check:
> > http://www.mysql.com/manual.php (the manual)
> > http://lists.mysql.com/ (the list archive)
> >
> > To request this thread, e-mail <[EMAIL PROTECTED]>
> > To unsubscribe, e-mail
><[EMAIL PROTECTED]>
> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
> >
> >
>
>
>---------------------------------------------------------------------
>Before posting, please check:
> http://www.mysql.com/manual.php (the manual)
> http://lists.mysql.com/ (the list archive)
>
>To request this thread, e-mail <[EMAIL PROTECTED]>
>To unsubscribe, e-mail
><[EMAIL PROTECTED]>
>Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Know thyself? Absurd direction!
Bubbles bear no introspection. -Khushhal Khan Khatak
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php