如何优化此查询并替换MAX函数?

时间:2014-07-09 02:15:53

标签: sql sql-server sql-server-2008 sql-server-2005 query-optimization

SELECT MAX(f_orderInteractionID)                
FROM  tOrders O              
INNER JOIN tOrderInteractions  OI    ON OI.fk_orderID = O.f_orderID                
GROUP BY OI.fk_orderID

有没有办法替换max函数,因为在实际执行计划中它使用了Index扫描,我更喜欢使用Index seek。如何改进此查询

1 个答案:

答案 0 :(得分:0)

要执行此操作,请重试

SELECT f_orderInteractionID
FROM  tOrders O              
INNER JOIN tOrderInteractions  OI    ON OI.fk_orderID = O.f_orderID
ORDER BY f_orderInteractionID DESC
LIMIT 1