Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to find max value of query using group by

Status
Not open for further replies.

dognobbler

Programmer
Joined
Jul 4, 2003
Messages
46
Location
GB
When I run the following query

select count( username) as count, username
from friends
where status="validated"
group by username
order by count;

it gives me a list of each username in the and how many times it appears in the friends table

Can anyone tell me how to rewrite this query so that it tells me which username appeared the most times in the friends table.

Thanks

Andy
 
select
username, count(username) as usercount from
foo
group by
username
order by
usercount desc
limit
1


is one way.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top