title: nested select in sql server 2008
body: <p>I save user logins in a table that named loginstats, I want to retrieve last login of every users, I use these code but I meet some error, What is my mistake?</p>
  
  <pre><code>select *
  from loginStats
  where id in (
      select distinct username, MAX(id) as id
      from loginStats
      group by username)
  </code></pre>