--- whoisquilty <[EMAIL PROTECTED]> wrote: > --- In [email protected], James Keeline <[EMAIL PROTECTED]> wrote: > > > > SELECT vidno, COUNT(*) AS popular FROM tablename GROUP BY vidno ORDER BY > > popular DESC LIMIT 10; > > > > James > > > Wow, that worked. Thanks, James. > > If I wanted to implement a ratings system, would I use the same > technique just with AVG()? > > Jeremy
Yes, if you have another field (rating) with integer values like 1 to 5 you could use AVG(rating). As you may have noticed, GROUP BY eliminates duplicates and sorts in ascending order by the field named in GROUP BY. That is why I had to add the ORDER BY ... DESC clause to control the output. The LIMIT should be self explanatory. MIN(), MAX(), AVG(), COUNT(), SUM() are examples of aggregate functions which can (and often must) be used with GROUP BY. James
