Rearranged array returned by query