Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - combination of MIN and COUNT

This is in Oracle database. Say I have the following table A:

column1 column2
id1       a
id2       a 
id3       a
id4       b
id5       b
id6       c

So what I want the sql does is: First count there's three As and two bs and one c, then based on the counts return me the smallest number of these counts, in this case is 1 (because we only have one c)

Can this be achieved somehow by using the combination of MIN and COUNT?

like image 671
neo Avatar asked Dec 06 '25 14:12

neo


1 Answers

In Oracle you can do this directly; count per group and use MIN on the results to get back one row with the desired value.

select min(count(*))
from tablea
group by column1;
like image 186
Thorsten Kettner Avatar answered Dec 08 '25 06:12

Thorsten Kettner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!