2uzhan.com
Advertisement
Now Place:2uzhan.com » How to finding the maximum value

How to finding the maximum value

MySQL @ October 15, 2005   Views:0

Hi All

I tried to find the maximum value by using count and group by statement
but the result is negative. how should i go about.

Let say the data are

empno | name
1 John
2 John
3 Jess

select count(name) from employment
group by empno

The above SQL statement will give

count(name)
2
1

But I want the value 2 only.

How should I go about?

--------------Solutions-------------

Hi
If the mysql version you use is ok with subqueries try

SELECT MAX(count_col) FROM
( SELECT COUNT(col1) AS count_col FROM tablename
GROUP BY col1
) AS t1 Thiam Joo Tay wrote:

> Let say the data are
>
> empno | name
> 1 John
> 2 John
> 3 Jess
>
> select count(name) from employment group by empno
>
> The above SQL statement will give
>
> count(name)
> 2
> 1
>
> But I want the value 2 only.
>
> How should I go about?

SELECT COUNT(name) AS c FROM employment GROUP BY empno ORDER BY c DESC LIMIT 1;

--
felix
Please use BBCode to format your messages in this forum.

Tags:
© 2018 2uzhan.com Contact