Return to Snippet

Revision: 48545
at July 5, 2011 00:38 by samwa


Initial Code
SELECT
    c.FirstName,
    c.LastName,
    o.OrderDate,
    o.OrderAmount
FROM Customers c
JOIN Orders o ON o.CustomerId = c.CustomerId
WHERE 
    o.OrderDate  =
    (
        SELECT TOP(1)
            o1.OrderDate
        FROM Orders o1
        WHERE 
            o1.CustomerId = o.CustomerId
        ORDER BY
            o1.OrderDate DESC
    )

Initial URL
http://sqlblog.com/blogs/adam_machanic/archive/2008/02/08/who-s-on-first-solving-the-top-per-group-problem-part-1-technique.aspx

Initial Description

                                

Initial Title
sql group by top

Initial Tags
sql

Initial Language
SQL