I have an Access database that I am interacting with using JET with the following structure:
ID UsersID
1 1
2 2
3 2
4 3
5 1
What I am trying to do is get the latest unique entries. eg:
ID UsersID
5 1
4 3
3 2
However, I am having trouble mixing grouping and ordering. I have tried
SELECT DISTINCT [UsersID] FROM [Table] ORDER BY [ID] DESC
SELECT [UsersID] FROM [Table] GROUP BY [UsersID] ORDER BY [ID] DESC
But, no luck. Note: if I leave off the ORDER BY [ID] DESC from either query, it works, but obviously the ordering is not as expected.
You can get the largest ID value for each UserID with a simple GROUP BY query.
However I’m not sure I understand the order by and latest 5 requirements. If latest 5 means the 5 largest ID values from the above query, then try it this way …
“Table” is not the best name for a table. Hope your real world situation uses a different table name. 🙂