I have a table:
Invoice | Status | Date | Explanation |
---|---|---|---|
44587 | 1 | 02.03.2022 | Awaiting update |
44587 | 2 | 07.03.2022 | Processed |
What i really want is to just get the row with the latest date. but since i really want the Explanation column, i keep getting two results...
I try with this:
SELECT d.Invoice, d.Status, Max(d.Date), d.Explanation
FROM InvoiceLog d
WHERE d.Invoice = 44587
GROUP BY d.Invoice, d.Status, d.Explanation
CodePudding user response:
this will return the row with the latest 'Date' (Assuming the column's type is indeed Date)
SELECT *
FROM InvoiceLog
WHERE Invoice = 44587
ORDER BY Date DESC LIMIT 1