Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * My full data. It's purely made up for an example.
- */
- [
- {
- "userId": 10,
- "timestamp": 1000
- },
- {
- "userId": 10,
- "timestamp": 500
- },
- {
- "userId": 5,
- "timestamp": 10
- },
- {
- "userId": 5,
- "timestamp": 1500
- },
- {
- "userId": 5,
- "timestamp": 50
- }
- ]
- /**
- * What I want to recieve
- *
- * Notice the userId is unique and only the largest timestamp is retrieved
- */
- [
- {
- "userId": 10,
- "timestamp": 1000
- },
- // {
- // "userId": 10,
- // "timestamp": 500
- // },
- // {
- // "userId": 5,
- // "timestamp": 10
- // },
- {
- "userId": 5,
- "timestamp": 1500
- },
- // {
- // "userId": 5,
- // "timestamp": 50
- // }
- ]
- /**
- * What I actually receive with my query shown in the stackoverflow question
- */
- [
- {
- "userId": 10,
- "timestamp": 1000
- },
- {
- "userId": 10,
- "timestamp": 500
- },
- // {
- // "userId": 5,
- // "timestamp": 10
- // },
- // {
- // "userId": 5,
- // "timestamp": 1500
- // },
- // {
- // "userId": 5,
- // "timestamp": 50
- // }
- ]
Add Comment
Please, Sign In to add comment