Used sortedArrayFromSQL function to shorten SQL retrieval