mysql - How to find the minimum values of a query's column -


how find minimum value of column of query?

my table x's data looks this:

(id, something, userid, something) values  ('r001','something','u0006','something'), ('r002','something','u0014','something'), ('r001','something','u0006','something'), ('r002','something','u0015','something'), ('r003','something','u0003','something'), ('r001','something','u0014','something'), ('r001','something','u0002','something'); 

my query, looks this:

select distinct userid, count( id ) count x group userid order count desc  

and query returns:

userid  count u0006   2 u0014   2 u0002   1 u0003   1 u0015   1 

how minimum values of count in query, bearing in mind there multiple minimum values?

the return want query this:

userid u0002 u0003 u0015 

thanks, in advance :)

you can using having clause:

select userid, count( id ) count x group userid having count(id) = (select min(cnt)                     (select count(id) cnt                           x                           group userid                          ) xx                    ); 

using select distinct group by redundant.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -