So I want to get the row with the most recent date, max(asofdate) but I am MySQL illiterate and can't seem to get it. It my head select * from Reports.InternalLoanExposureFlat where asofdate = max(asofdate) seems to make sense but the console seems to disagree with me.
Thanks in advance.
To find the max value of a column, use the MAX() aggregate function; it takes as its argument the name of the column for which you want to find the maximum value. If you have not specified any other columns in the SELECT clause, the maximum will be calculated for all records in the table.
SQL MIN() and MAX() Functions The MIN() function returns the smallest value of the selected column. The MAX() function returns the largest value of the selected column.
MAX() function with HavingThe SQL IN OPERATOR which checks a value within a set of values and retrieve the rows from the table can also be used with MAX function.
Another solution that is described below with code examples can be used to solve the same issue Sql Max Of Two Values. SELECT MAX (column_name) FROM table_name WHERE column_name NOT IN (SELECT Max (column_name) FROM table_name);
If you don't want the risk of returning multiple results then you should use this:
SELECT *
FROM Reports.InternalLoanExposureFlat
ORDER BY asofdate DESC
LIMIT 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With