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

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

sigmas
Posting Yak Master

Belarus
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
From
(
Select dense_rank() over(partition by employeeID order by orderdate desc) as rnk,
*
From orders
)d
Where rnk = 1;

LoztInSpace
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

LoztInSpace
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  
 New 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.05 seconds. Powered By: Snitz Forums 2000