And if you wanted to find out the latest thing that happened in January to each...DECLARE @tablea TABLE ( employeeID INT , [name] VARCHAR(50) )DECLARE @tableb TABLE ( [Id] INT IDENTITY(1,1) , [employeeID] INT , [startDate] DATETIME , [value] VARCHAR(50) )INSERT INTO @tablea VALUES (10, 'Mr Green')INSERT INTO @tablea VALUES (11, 'Mr Black')INSERT INTO @tableb VALUES (10, '2008-01-01', 'Gangster Training A')INSERT INTO @tableb VALUES (10, '2008-01-02', 'Advanced GT B')INSERT INTO @tableb VALUES (11, '2008-01-01', 'Goon Training A')INSERT INTO @tableb VALUES (11, '2008-02-02', 'Adv Goon Training A')INSERT INTO @tableb VALUES (11, '2008-06-01', 'Burial - Goon Hall B')SELECT a.[name] , b.[startDate] , b.[value]FROM @tablea a JOIN ( SELECT b.[employeeId] AS empId , MAX(b.[Id]) AS tablebId FROM @tableb b WHERE DATEDIFF(MONTH, b.[startDate], '2008-01-01') = 0 GROUP BY b.[employeeId] ) hTableb ON hTableb.[empId] = a.[employeeId] JOIN @tableb b ON b.[Id] = hTableb.[tablebId]
That kind of thing.-------------Charlie