Record with Max Date from Table T2

  • Hi
      I have below code and i want record with Max Date from Table 2

    SELECT * FROM dbo.Employee T1 Left join dbo.Employee_Details T2
                on T1.EmployeeID = T2.EmployeeID order by T1.EmployeeID

    Thanks

  • At a complete guess...

    [Code]SELECT {YourColumns}
    FROM Table1 T1
         OUTER APPLY (SELECT TOP 1 {columns}
                      FROM Table2 oa
                      WHERE oa.EmployeeID = T1.EmployeeID
                      ORDER BY {YourDateColumn} DESC) T2;[/code]

    You'll need to correct the parts in the braces, as I don't have any sample data/DDL to base the query on.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply