The table in chronological order records the states of users (and their changes), for example,
datetime | uid | status 2016-07-01 | 14 | Register 2016-07-01 | 14 | Active 2016-07-02 | 15 | Active 2016-07-02 | 16 | Register 2016-07-02 | 14 | Pending 2016-07-04 | 16 | Pending
How to formulate a MySQL query correctly in order to get
datetime | uid | status 2016-07-02 | 15 | Active 2016-07-02 | 14 | Pending 2016-07-02 | 16 | Pending
That is, how is it possible in the MySQL query to indicate that only the most recent states for the unique uids are output? I tried GROUP BY
, DISTINCT
and MAX()
, but the time displays exactly the maximum, and the status value is not the maximum.
PS The table itself gave a schematic, the time is fixed up to a second, there are no intersections in time. Just the last entry for each of the uid is needed. I would be grateful for at least a hint in which direction to look.
select distinct uid
, then inner join with the same table to get the date and status. - nzeemin