I have the following table in MySQL with an auto-increment ID field and an auto timestamp field(not mentioned here). I am trying to group by the rows on order# and get the latest row.
Order Table -
id | order# | status |
---|---|---|
1 | 100 | pending |
2 | 100 | processing |
3 | 100 | delivered |
4 | 101 | pending |
5 | 101 | processing |
6 | 101 | cancelled |
Expected Answer -
id | order# | status |
---|---|---|
3 | 100 | delivered |
6 | 101 | cancelled |
So far this is all I could come up with. I spend few hours trying to google a solution, but couldnt find something clear.
SELECT * FROM TABLE ORDER BY order# , id DESC;