title: SELECT latest record from a SQL Server 2008 table
body: <p>I have a table which contains the terms of payment for a product. I want to get the latest terms for that product. In the query below it returns all the terms since my application went into production. I only need the latest term for that product.</p>
  
  <pre><code>SELECT
     dbo.FinishProduct.id,
     dbo.PaymentTerm.id,
     dbo.PaymentTerm.terms,
     dbo.PaymentTerm.type
  FROM
     dbo.PaymentTerm
  INNER JOIN
     dbo.FinishProduct ON (dbo.PaymentTerm.finishProductId = dbo.FinishProduct.id) 
  WHERE
     finishproduct.id = 39
  </code></pre>
  
  <p>My <code>PaymentTerm</code> table has PK <code>id</code> and it has date when it was created and updated, like this:</p>
  
  <pre><code>id BIGINT NOT NULL IDENTITY,
  created DATETIME,
  lastUpdated DATETIME,
  </code></pre>