Reputation: 1151
Suppose I have a bucket of documents in Couchbase like below.
user lastUpdate otherField1
a "2015-12-06" 1
a "2015-11-06" 2
b "2015-12-05" 3
b "2015-10-05" 4
How could I obtain in a single N1QL query the last updated document for each user ? I've started using N1QL a few days ago and I don't know how to do such complex queries. Thank you
Upvotes: 1
Views: 357
Reputation: 2445
You can do the following:
SELECT user, MAX( [ lastUpdate, doc ] ) AS pair
FROM my_bucket AS doc
GROUP BY user;
Upvotes: 2