How to get the name for a maximum or minimum value from a table

@hjie30 What is the datatype of minval?.Change it to double and try again