troubleshooting Question

MSSQL Query: Help with sorting "Top Sales Agent" with lower [ID] as the tie breaker.

Avatar of Ron Malmstead
Ron MalmsteadFlag for United States of America asked on
Microsoft SQL ServerSQL
5 Comments1 Solution7 ViewsLast Modified:

Need help sorting "Top Sales Agent" ... when there needs to be a tiebreaker..

The tie breaker is the agent who made their sale first, which is the lower [id] in the table.

Example desired output...(when there is one clear winner.)

[Agent Name],[Sale Count],[ID]


Bill, 1, 1000

Jenny, 1, 1001

Debbie, 1, 1002

When there are tie breakers...

[Agent Name],[Sale Count],[ID]
Bill, 1, 1000
Jenny, 1, 1001
Debbie, 1, 1002


I don't actually need the [ID] of course, it just needs to be able to be sorted in this manner... where [ID] represents the lowest [ID] number for that agent... (their first order of the day)

Summary: If the agents all had 1 order, the agent who got the first order wins.  If two agents have 2 orders, and everyone else has 1, the agent with the lowest [id] of the top two, wins.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros