Listing 1: Measurements for Instruments SELECT f.InstrId , (SELECT TOP 1 m.Msr1 FROM dbo.InstrStats AS m WHERE m.InstrId = f.InstrId AND m.Msr1 IS NOT NULL ORDER BY m.CreateTime DESC) AS l_msr1 , (SELECT TOP 1 m.Msr2 FROM dbo.InstrStats AS m WHERE m.InstrId = f.InstrId AND m.Msr2 IS NOT NULL ORDER BY m.CreateTime DESC) AS l_msr2 , (SELECT TOP 1 m.Msr3 FROM dbo.InstrStats AS m WHERE m.InstrId = f.InstrId AND m.Msr3 IS NOT NULL ORDER BY m.CreateTime DESC) as l_msr3 , (SELECT TOP 1 m.Msr4 from dbo.InstrStats AS m WHERE m.InstrId = f.InstrId AND m.Msr4 IS NOT NULL ORDER BY m.CreateTime DESC) AS l_msr4 , (SELECT TOP 1 m.Msr5 FROM dbo.InstrStats AS m WHERE m.InstrId = f.InstrId AND m.Msr5 IS NOT NULL ORDER BY m.CreateTime DESC) AS l_msr5 , (SELECT TOP 1 m.Msr6 FROM dbo.InstrStats AS m WHERE m.InstrId = f.InstrId AND m.Msr6 IS NOT NULL ORDER BY m.CreateTime DESC) AS l_msr6 FROM dbo.InstrStats AS f GROUP BY f.InstrId