• To get the data for the most recent row, use row_number:

    LEFT JOIN (SELECT UserID, AdressID,

    rowno = row_number() OVER (PARTITION BY AdressID ORDER BY OrderID DESC)

    FROM Orderhistory) AS OH ON A.AdressID = OH.AddressID

    AND OH.rowno = 1

    [font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]