Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

optimizing a sql server query

Avatar of aturetsky
aturetsky asked on
Microsoft SQL Server 2005SQL
10 Comments1 Solution289 ViewsLast Modified:
I have a table called customer_access that keeps track of what users have access to what customer.
I need to get a list of customer_access records that would give me the list of records where the approval_date is the latest for each of the user-customer combinations.

Currently, I am doing it this way, but I have a feeling that it can be done more elegantly.  I am looking to improve the clarity of the sql w/o hurting the performance (or, ideally, improving performance as well).

select * from (select row_number() over (partition by ca.customerId, ca.userId ORDER BY ca.approvalDate DESC) as rownumber, ca.id from customer_access ca) ca1 where ca1.rownumber = 1

Avatar of reb73
reb73Flag of Ireland image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answers