Compete to give the most efficient query that returns a column grouped by key based on the most recent date of another column.
I will run your queries against a 359,000 row table I have on a production server. This table records certain information about certain occurrences.
CREATE TABLE DoneHistory (
Thing char(20) NOT NULL,
TimeDone datetime NOT NULL,
PlaceDone char(10) NOT NULL,
OtherInfo1 char(10) NULL,
OtherInfo2 char(10) NULL,
OtherInfo3 char(10) NOT NULL
)
The table has two nonclustered indexes but no clustered index. I'm willing to test against other tables that do have clustered indexes but this one simply does not (and don't ask me why, I don't know).
Indexes:
Thing
Thing, OtherInfo3
Expected output:
Thing, TimeDone (max per Thing), PlaceDone (from the same row as the TimeDone).
I do have a particular query in mind that beat the pants off the other ones I tried. So I both wanted to share it with you but also see if anyone else can find it.
I will run your queries against a 359,000 row table I have on a production server. This table records certain information about certain occurrences.
CREATE TABLE DoneHistory (
Thing char(20) NOT NULL,
TimeDone datetime NOT NULL,
PlaceDone char(10) NOT NULL,
OtherInfo1 char(10) NULL,
OtherInfo2 char(10) NULL,
OtherInfo3 char(10) NOT NULL
)
The table has two nonclustered indexes but no clustered index. I'm willing to test against other tables that do have clustered indexes but this one simply does not (and don't ask me why, I don't know).
Indexes:
Thing
Thing, OtherInfo3
Expected output:
Thing, TimeDone (max per Thing), PlaceDone (from the same row as the TimeDone).
I do have a particular query in mind that beat the pants off the other ones I tried. So I both wanted to share it with you but also see if anyone else can find it.