Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Top 1 per each customer
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

172 Posts

Posted - 07/17/2013 :  15:13:48  Show Profile  Reply with Quote
Is there an efficient index for this query?

use northwind
Select orderid, customerid, employeeid, orderdate, RequiredDate
Select dense_rank() over(partition by employeeID order by orderdate desc) as rnk,
From orders
Where rnk = 1;

Aged Yak Warrior

940 Posts

Posted - 07/17/2013 :  15:49:04  Show Profile  Reply with Quote
possibly employeeID, orderdate desc
but depends on how much data you have and what else is going on.
Go to Top of Page

Aged Yak Warrior

940 Posts

Posted - 07/17/2013 :  18:14:24  Show Profile  Reply with Quote
What are you hoping for? You can't answer that query without a scan on either an index or a table.

Edited by - LoztInSpace on 07/17/2013 18:24:38
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000