In MySQL I'm tasked with the following accounting task:
- I have to find the entire row with the newest date in month (given month number)
- Where text = b
I took a snippet from the database to demonstrate my problem.
input:
date text
---------- ----
2015-05-01 b
2015-04-30 a
2015-04-29 b
2015-04-29 a
2015-04-28 b
expected:
date text
---------- ----
2015-04-29 b
I have tried the following:
SELECT MAX(date), text
FROM table1
WHERE MONTH(date) = 4
AND text = b
But it does not return the correct text. I have tried solving the problem using this link SQL Select only rows with Max Value on a Column - but I can't get it to work.
What to do?