I'm doing a query on a log table that contains the action taken and where the action was taken. For instance, if a record is modified, it inserts into this log table. I have a view that is grabbing the latest update date, but it's quite slow because it's using top 1. Also, the select list is quite large, so doing a group by is even slower then using select top 1. Here is the select statement and the table definitions:CREATE TABLE UserLog ( [LogID] int identity, [UserID] int, [ActionID] int, [ActionDt] datetime, [LocationID] int)CREATE TABLE [User] ( [UserID] int identity primary key, [FirstName] varchar(255), [LastName] varchar(255), [Deleted] bit)select FirstName, LastName, UpdateSource = (select top 1 LocationID from UserLog where UserID= u.UserID and ActionID in (1,5) order by ActionDt desc), UpdateDt = (select max(ActionDt) from UserLog where UserID= u.UserID and ActionID in (1,5))from [User] u
any ideas on optimization?