title: SQL Server Group By Order By Where
body: <p>I have a single table which I need to pull back the 5 most recent records based on a userID and keying off of documentID (no duplicates).  Basically, I'm tracking visited pages and trying to pull back the 3 most recent by user.</p>
  
  <p>Sample data:</p>
  
  <pre><code>╔══════════════════════════════════════════════╗
  ║UserID   DocumentID   CreatedDate             ║
  ╠══════════════════════════════════════════════╣
  ║  71         22       2013-09-09 12:19:37.930 ║
  ║  71         25       2013-09-09 12:20:37.930 ║
  ║  72          1       2012-11-09 12:19:37.930 ║
  ║  99         76       2012-10-10 12:19:37.930 ║
  ║  71         22       2013-09-09 12:19:37.930 ║
  ╚══════════════════════════════════════════════╝
  </code></pre>
  
  <p>Desired query results if UserID = 71:</p>
  
  <pre><code>╔══════════════════════════════════════════════╗
  ║UserID    DocumentID  CreatedDate             ║
  ╠══════════════════════════════════════════════╣
  ║  71         25       2013-09-09 12:20:37.930 ║
  ║  71         22       2013-09-09 12:19:37.930 ║
  ╚══════════════════════════════════════════════╝
  </code></pre>