Find minimum record based on two fields, self joins vs. derived tables Is there a better way? I need attributes of the oldest SequenceID of oldest DateID for each ThingID. PK is DateID &amp; SequenceID:

SELECT
          ThingID     = F1.ThingID
        , Attribute1  = F1.Attribute1
        , Attribute2  = F1.Attribute2
        , Attribute3  = F1.Attribute3
FROM dbo.Fact F1
INNER JOIN (
              SELECT  DateID      = F2.DateID
                    , SequenceID  = min(SequenceID)
                    , ThingID     = F2.ThingID
              FROM dbo.Fact F2
              INNER JOIN  (
                              SELECT    DateID   = min(DateID)
                                      , ThingID  = ThingID
                              FROM      dbo.Fact
                              GROUP BY  ThingID

                          ) AS F3 ON  F2.ThingID = F3.ThingID
                                  AND F2.DateID  = F3.DateID

              GROUP BY F2.DateID, F2.ThingID

            ) AS F2  ON   F1.ThingID    = F2.ThingID
                    AND   F1.SequenceID = F2.SequenceID
                    AND   F1.DateID     = F2.DateID


FACT TABLE

DateID       datetime  PK
SequenceID   INT       PK
ThingID      INT
AttributeID1 INT
AttributeID2 INT
AttributeID3 INT


edit: SQL 2012
You can use window functions for this:

WITH ct AS
  ( SELECT
        ThingID,
        Attribute1,
        Attribute2,
        Attribute3,
        Rn = ROW_NUMBER() OVER (PARTITION BY ThingID
                                ORDER BY DateID, SequenceID)
    FROM dbo.Fact
  ) 
SELECT
    ThingID,
    Attribute1,
    Attribute2,
    Attribute3
FROM ct
WHERE Rn = 1 ;


and an index on (ThingID, DateID, SequenceID).