Modified sql query to grab by each person, refactored code