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.
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
SELECT * FROM Reports.InternalLoanExposureFlat WHERE asofdate = (SELECT MAX(asofdate) FROM Reports.InternalLoanExposureFlat)
I agree with the console ;-).
The max function returns the maximum of a group or the complete table.
SELECT somecolumn, MAX(asofdate) FROM mytable GROUP BY somecolumn SELECT MAX(asofdate) FROM mytable