Hi,
Change the 2nd like this you will get the result
select
distinct
i.iphone_id,
i.seriel_number,
lh.Last_Date_Assigned,
loc.emp_name,
loc.Department
from iphones i
inner join (
select iphone_id, MAX(date_assigned) as Last_Date_Assigned
from location_history group by iphone_id
)lh
join location_history loch on loch.date_assigned = lh.Last_Date_Assigned and loch.iphone_id=lh.iphone_id
join locations loc on loc.location_id = loch.location_id
on i.iphone_id = lh.iphone_id