I have a table, which contains logs and has the following scheme:
USER | DATE | LOG
x x x
...
Now, I want to make ONE query to retrieve every (USER, DATE)
pair, where DATE
is the latest for this user.
I was thinking about something like (pseudo):
SELECT ... FROM (TABLE) ORDERED BY DATE, DISTINCT BY USER
But I'm not sure if that's gonna work.
Is it correct that DISTINCT
would take the first possible dates in this query, therefore yielding the required result? Or the order of elements in DISTINCT
query is undefined?
If yes, how should I solve this problem (this is the case I can't add new table, such as users
and, for example, cache the lastest dates there)?