i think you can just do something like this...

select 
    count(product_id) as number_of_product, product_id 

from
    table_name

group by 
    product_id

order by 
    product_id

----- Original Message ----- 
From: "Kay Smoljak" <[EMAIL PROTECTED]>
To: "SQL" <[EMAIL PROTECTED]>
Sent: Tuesday, November 27, 2001 11:02 PM
Subject: DISTINCT COUNT - SQL Server


> Hi all,
> 
> This is probably really simple, but I just can't seem to get it!
> 
> To simplify, I have an orders table, with a primary key "OrderID", and a
> foreign key "ProductID". I want to get the top five most ordered
> products. I thought maybe using a COUNT with DISTINCT, and restricting
> the rows returned, but how do I ORDER BY?
> 
> Any help on how to approach this will be greatly appreciated.
> 
> Thanks,
> K.
> 
> 
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to