I have table:
id | uid | action
-----------------
1 | 1 | 2
2 | 3 | 1
3 | 2 | 2
4 | 3 | 2
5 | 1 | 1
How can I select uid’s with last action for example 1? In this case only last line.
UPDATE: As you can see for uid=3 at first we have action=1, then action=2 it menas that uid=3 is not “good” line for us. But for uid=1 last action is 1, so that “good” line.
UPDATE2: action=1 is enter and action=2 is exit. Finaly I need to get list of users who in building now, or at least list of last action of every user.
Edit: I added some explanations at the end of my answer.
Results:
Explanations:
The query from derived table
(...) xwill produce folowing results: