8
I have the following table:
status_invoices
id_fatura | status | data
----------------------------------------
XX-XX-XX | 3 | 2017-01-04 21:00:24
XX-XX-XX | 2 | 2017-01-02 11:10:20
YY-YY-YY | 4 | 2017-01-04 21:00:24
YY-YY-YY | 1 | 2017-01-02 11:10:20
----------------------------------------
How can I mount a query to return me (id_invoice, status, date) of the last status change?
The result of the consultation should be something like:
id_fatura | status | data
----------------------------------------
XX-XX-XX | 3 | 2017-01-04 21:00:24
YY-YY-YY | 4 | 2017-01-04 21:00:24
----------------------------------------
How to do this in an SQL query? Thank you in advance!
This is cool, from DB to DB have different tricks to achieve this. In Sqlite, in recent versions, would be enough a
MAX()
in the columndata
to force the columnstatus
track (and this is a documented resource). In MysqlORDER BY ... DESC
works, but there is no promise to always be so in future verses.– Bacco
So... I tried in ways that I thought would work, but it turned out that the status did not follow. Excellent trick kk
– LocalHost