Home Forums SQL Server 2008 T-SQL (SS2K8) how to write join part of query so that only most recent equipment assignments are returned RE: how to write join part of query so that only most recent equipment assignments are returned

  • does this work for you ...?

    with cte as

    (

    SELECT iphone_id, MAX(date_assigned) AS Maxd

    FROM location_history

    GROUP BY iphone_id

    )

    SELECT iPhones.iphone_id,

    iPhones.seriel_number,

    cte.Maxd,

    locations.Emp_name,

    locations.Department

    FROM iPhones

    INNER JOIN cte ON iPhones.iphone_id = cte.iphone_id

    INNER JOIN location_history ON cte.iphone_id = location_history.iphone_id

    AND cte.Maxd = location_history.date_assigned

    INNER JOIN locations ON location_history.location_id = locations.location_id

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day