tags:

views:

274

answers:

2

I have the following table (simplified) in an oracle db:

productId  |  modelDescription 
         1 |             thing
         2 |     another thing
         3 |       not a thing
         4 |             thing

I want to select the modeldescription which has the highest appearence in this table. The problem is that there can be nearly infinite model descriptions. So the resultset should look like something like this:

modelDescription | appearance 
           thing |          2 
   another thing |          1 
             ... |        ...
+3  A: 
select modeldescription, count(modeldescription) 
from products 
group by modeldescription
order by 2 desc
Dead account
thaks thats exactly what i was looking for
Red33mer
+1  A: 

In addition, if you only want the highest add the following:

Select Top 1 modeldescription......

Tanner