fixed query to get last