Fetch result of query twice
Since fetchAllKeyed() internally uses foreach loop to sort the data, the answer given by  Suranga Panagamuwa Gamage to use fetchAssoc() and then a loop seems the most efficient way.