12 messages in com.mysql.lists.mysqlRe: How do I select something distinc...
FromSent OnAttachments
Sinisa Milivojevic25 Jan 2002 20:26 
Mike Nelson25 Jan 2002 23:43 
Venu26 Jan 2002 11:14 
Paul Reilly26 Jan 2002 12:10 
Jeremy Zawodny26 Jan 2002 12:24 
D'Arcy Rittich01 Feb 2002 06:50 
Sinisa Milivojevic01 Feb 2002 07:05 
SED01 Feb 2002 07:56 
Paul DuBois01 Feb 2002 08:19 
Paul DuBois01 Feb 2002 08:31 
Venu01 Feb 2002 10:17 
Victoria Reznichenko01 Feb 2002 13:17 
Subject:Re: How do I select something distinct ordered by most frequent? (e.g. top 10)
From:Paul DuBois (pa@snake.net)
Date:02/01/2002 08:31:57 AM
List:com.mysql.lists.mysql

At 10:19 -0600 2/1/02, Paul DuBois wrote:

At 15:56 +0000 2/1/02, SED wrote:

Hi,

I'm trying to make a query where I select something distinct ordered by most frequent?

I found below example from the manual but I can not figure out how I should order them by most frequent - do you know how?

SELECT DISTINCT owner FROM pet

Don't use distinct in that case. Count them and order by the descending counts.

SELECT owner, COUNT(owner) AS frequency FROM pet ORDER BY frequency DESC;

Oops. Forgot the GROUP BY:

SELECT owner, COUNT(owner) AS frequency FROM pet GROUP BY owner, ORDER BY frequency DESC;