how do I get the 2 most recent records

Posted by fishhead on Stack Overflow See other posts from Stack Overflow or by fishhead
Published on 2010-06-05T12:09:37Z Indexed on 2010/06/05 12:12 UTC
Read the original article Hit count: 212

Filed under:
|

I have a table similar to the example shown below. I would like to be able to select the two most recent entrys for each accountNo. I am using Microsoft SQL. Thank you for any help that you can provide.

AccountNo,  DateOfOrder,    OrderID
-----------------------------------------
 123,        March 1 2010,     1
 222,        March 3 2010,     2
 123,        April 1 2010,     3
 345,        March 15 2010,   77
 123,        june 1 2010,     55
 123,        march 5 2010,    33
 345,        march 1 2010,    99
 222,        june 1 2010,     7
 222,        june 2 2010,  22

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server