How to get results from database SQL query

I need to get results from SQL query to database.

I have an SQL statement, e.g.: SELECT MAX(my_field) max_my_field FROM
my_table WHERE id=5

I want to get the result, what is the max value. I have to get only one
record with a number, or null if no records found. Please provide Ruby
code to do this? (to store results in variable)

On Nov 18, 3:23 pm, Yan O. [email protected] wrote:

I need to get results from SQL query to database.

I have an SQL statement, e.g.: SELECT MAX(my_field) max_my_field FROM
my_table WHERE id=5

I want to get the result, what is the max value. I have to get only one
record with a number, or null if no records found. Please provide Ruby
code to do this? (to store results in variable)

Checkout the maximum method (Peak Obsession
ActiveRecord/Calculations/ClassMethods.html#M001659)

Fred