0

If I have a table like below:

ID   A B C D(ate)
ASDF 1 2 1 12/12/2016
ASEF 1 2 3 12/13/2016
AFDS 2 3 1 12/13/2016
ASFA 2 3 4 12/14/2016

And I want to get the latest based on a pair (A, B) and the latest date (D), how would I set up a table to work well with this request, and what kind of query would I use to retrieve that?

The output would give me values for the IDs ASEF and ASFA.

I'm using the aws-go-sdk to run this, but I should be able to convert any solution to that SDK.

Nathan Hyland
  • 842
  • 2
  • 13
  • 28

1 Answers1

0

You should use attribute A as HashKey(PartitionKey) and Date as RangeKey(SortKey). With partitionKey only equality condition(==) can be used. RangeKey supports <,>,=,Between operations.

Check this link

cerberus
  • 531
  • 4
  • 14
  • You're saying ID should not be the hash key? It's the only unique row in the table, thought I read that should mean it's the hash. Also trying to see how I could use the range key to get the latest of each A/B combination. – Nathan Hyland Apr 24 '18 at 13:15
  • @NathanHyland you can use ID attribute as primary index. Create a Global secondary index with A attribute as partition key and Date as Sort Key. – cerberus Apr 24 '18 at 13:44