Get the Min and max value from a query