select - Sql statement question -
i have table, contains logs , has following scheme:
user | date | log x x x ...
now, want make one query retrieve every (user, date)
pair, date
latest user.
i thinking (pseudo):
select ... (table) ordered date, distinct user
but i'm not sure if that's gonna work.
is correct distinct
take first possible dates in query, therefore yielding required result? or order of elements in distinct
query undefined?
if yes, how should solve problem (this case can't add new table, such users
and, example, cache lastest dates there)?
now, want make 1 query retrieve every (user, date) pair, date latest user.
select user, max(date) yourtable group user
you might want add order user
.
since both user , date reserved words sql dbms, more run.
select "user", max("date") "yourtable" group "user";
Comments
Post a Comment