I have a system that stores documents in a database, each user can create multiple documents and each document is saved in different versions. Each user has a unique token. Each document has a unique id. Each document is being stored many times but at different times.
Example of my table:
|AI |token |docid time|
|1 |id1 |doc1 1000|
|2 |id2 |doc2 1001|
|3 |id1 |doc1 909 |
|4 |id2 |doc1 1020|
|5 |id1 |doc3 801 |
What I need is a query that gives me only the newest of each document for a particular user.
So in this example I would like for user with token id1
:
1 id1 doc1 1000
5 id1 doc3 801
How would a query that achieve this look like?