select username , clicks from (select username , clicks , row_number() OVER (PARTITION BY username ORDER BY clicks desc ) AS Seq from yourtable) d
where d.seq =1
try this..
Main Topics
Browse All TopicsOk, I need to select the users in my database with the most clicks, but I don't want to display the same user over and over. An example of this type of sql statement would be:
SELECT DISTINCT TOP 15 UserName FROM Items ORDER BY Clicks DESC
I also do not need to display the clicks, just the usernames in Descending click order.
An example of the data in the database would be:
UserName | Clicks
Usernam1 | 2
Usernam1 | 8
Usernam1 | 3
Usernam2 | 5
Usernam2 | 6
after executing the SQL statement I would like to get:
Usernam1
Usernam2
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: brejkPosted on 2009-11-04 at 03:23:57ID: 25738205
If it's all about the totla clicks:
SELECT TOP 15 Username
FROM Items
GROUP BY Username
ORDER BY SUM(Clicks) DESC
If it's all about a maximum Clicks from a single record:
SELECT TOP 15 Username
FROM Items
GROUP BY Username
ORDER BY MAX(Clicks) DESC