• Hi,

    Attached is a script to build the tables with data.

    (rename to .sql of course).

    I tried to do for the start something like:

    SELECT Unit.Name, Unit.SerialNumber, Unit.Location, UD.PowerConsumptionValue, LastDate

    FROM Units Unit

    CROSS APPLY (

    SELECT TOP 1 UD.PowerConsumptionValue, MAX(UD.DateOfData) AS LastDate

    FROM UnitsData UD

    WHERE Unit.ID = UD.UnitID

    GROUP BY UD.PowerConsumptionValue

    ORDER BY LastDate DESC

    ) UD

    But it returns to me only one unit and not the others.

    Appreciate your kindly help.

    Thanks